[英]Android table layout formatting problems not fitting to screen
我正在使用带有3列标签,*和微调器的tablelayout,所有这些都具有wrap_content,并且在微调器文本较小时效果很好。 如果任何一个微调框的文本都非常长,则所有微调框的范围一直到结束,并且也不适合屏幕。
有什么方法可以使每个微调器适合其文本大小,如tablelayout中的wrap_content。 表布局示例的xml。
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:stretchColumns="2" >
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_column="0"
android:gravity="right"
android:paddingLeft="3dip"
android:text="Sold To"
android:textColor="#000033"
android:textSize="17sp" />
<TextView
android:layout_column="1"
android:gravity="left"
android:text="*"
android:textColor="#FF0000"
android:textSize="17sp"
android:width="20dip" />
<Spinner
android:id="@+id/sold_to_dd"
android:layout_width="wrap_content"
android:layout_column="2"
/>
</TableRow>
</TableLayout>
我希望很多人会遇到同样的问题。 提前致谢
您可以为每个微调器设置maxWidth
属性,也可以检查字符串的长度,即如果其长度> x(例如10),则放置在微调器中,然后使用子字符串fn从字符串中仅取(x-3)个字符字符串并在其后缀“ ...”,然后将该字符串放入微调框。 例如: StringABCDEFGHIJKLM
可以变成StringAB...
这是因为您仅拉伸了第二列,即旋转器。 您将必须在每个列上设置权重。 就像是
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
<TableRow>
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_column="0"
android:gravity="right"
android:paddingLeft="3dip"
android:text="Sold To"
android:textColor="#000033"
android:textSize="17sp" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_column="1"
android:gravity="left"
android:text="*"
android:textColor="#FF0000"
android:textSize="17sp" />
<Spinner
android:id="@+id/sold_to_dd"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="6"
android:layout_column="2"
android:singleLine="true"
/>
</TableRow>
</TableLayout>
权重将指示要占据的屏幕百分比。 因此每个textView将占据屏幕的20%,旋转器将占据60%。
您也可以参考以下内容: Android Holo主题不包含多行微调框下拉项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.