Rya*_*yan 6 android tablelayout
我在定位布局元素时遇到问题.我的TableLayout中的AutoComplete和它之后的按钮正在扩展TableRow大于屏幕的宽度.任何人都知道为什么?下面是我的XML代码以及问题的图片.
提前致谢!!
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView android:id="@+id/installation"
android:textSize="14sp" android:completionThreshold="3" />
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/btn_find" android:text="@string/btn_find"></Button>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/error" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingTop="20px"
android:textColor="#FF0000" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
小智 39
对于需要表格布局的那些,请使用layout_weight选项.见下面的代码.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6sp" android:id="@+id/detailsLayout">
<TableRow
android:layout_width="wrap_content"
android:id="@+id/TableRow03"
android:layout_height="wrap_content">
<TextView
android:id="@+id/TextView06"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Detail 1"></TextView>
<TextView
android:text="@string/empty_value"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/sessionAudience"
android:layout_weight="1"></TextView>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
默认情况下,在一个小部件TableRow
都有android:layout_width="wrap_content"
.这并不限制你的屏幕大小 - wrap_content
意味着"包装内容",而不是"包装内容,但如果你不介意,请不要离开屏幕的边缘".
在这种情况下,您不需要使用a TableLayout
和set TableRows
,因为您没有表.
因此,一种方法是使用a RelativeLayout
并AutoCompleteTextView
使用android:layout_alignParentLeft="true"
和android:layout_alignParentRight="true"
.这将把它固定到它的外边缘RelativeLayout
,你可以用它android:layout_width=fill_parent
来填充屏幕.
归档时间: |
|
查看次数: |
12999 次 |
最近记录: |