我在定位布局元素时遇到问题。我的 TableLayout 中的 AutoComplete 和它之后的按钮将 TableRow 扩展到大于屏幕宽度。任何人都知道为什么?下面是我的 XML 代码以及问题图片。
提前致谢!
<?xml version="1.0" encoding="utf-8"?>
<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>
最佳答案
对于那些确实需要表格布局的,请使用 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>
关于Android - 用户界面元素离开屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2951953/