【发布时间】:2014-05-21 14:48:18
【问题描述】:
我正在尝试做我的第一个复杂的 GUI,但现在我无法解决这个问题。
前两行的第一列只需要包含标签,而前两行的第二列必须占据剩余空间。
在这个快照中,我注意到的问题是第一列比我想要的要大。
这是实现该布局的一段代码。
...
...
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/linear_layout_background"
android:stretchColumns="*"
android:shrinkColumns="*">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp" >
<TextView
android:id="@+id/textViewPlateValueLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/plateValue"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/productID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/back"
android:ems="5"
android:text="@string/blank"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp" >
<TextView
android:id="@+id/ztlLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ztl"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/ztlShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/back"
android:text="@string/blank"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center" >
<TextView
android:id="@+id/isAllowed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/blank"
android:background="@drawable/back"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
...
...
此外,由于它们真的不切实际,我想请教您一些关于使用比这更好的方法的建议。
【问题讨论】:
-
我不认为 TableLayout 对你正在做的事情有好处。只需使用 RelativeLayout 和 LinearLayout。
-
如果您的要求允许,并且您不必必须将标签放在输入字段的左侧 - 看起来使用
TextInputLayout将是另一种方式解决这种统一的输入布局,遵循最佳实践design/widget/TextInputLayout
标签: android android-layout android-tablelayout