[英]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.