我在按钮点击事件上添加一个表格行。我的行有2个textview和2个微调器和1个EditText。我希望列的大小相同,但是根据所选值,微调器的大小会发生变化。请帮忙,分享一些灯光。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:stretchColumns="*"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_weight=".2"
android:background="@drawable/cell_shape"
android:padding="5dp"
android:text="S.No"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_weight=".2"
android:background="@drawable/cell_shape"
android:padding="5dp"
android:text="Product"
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="@drawable/cell_shape"
android:layout_weight=".2"
android:padding="5dp"
android:text="Product List"
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="@drawable/cell_shape"
android:layout_weight=".2"
android:padding="5dp"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
<TextView
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="@drawable/cell_shape"
android:layout_weight=".2"
android:padding="5dp"
android:text="Quantity"
android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
</TableRow>
<!--<TableRow
android:id="@+id/tr1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"/>-->
</TableLayout>
<TableLayout
android:id="@+id/tlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</TableLayout>
</LinearLayout>
<Button
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Add Item"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"><Button
android:id="@+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
/></LinearLayout>
</LinearLayout>
提前致谢
答案 0 :(得分:0)
如果微调器正在增长以匹配所选值,那么您很可能将layout_width
设置为wrap_content
听起来你应该使用更像layout_weight的东西来正确用尽水平空间
编辑: 如果它变得太大,我看不到这个视图会滚动到哪里。听起来你应该使用RecyclerView或ListView代替你的TableLayout。 列表中的每个项目都可能是:
<LinearLayout
android:layout_height="?android:attr/listItemPreferredHeight"
android:layout_width="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/some_text"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/some_more_text"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1">
</LinearLayout>
注意:写在我头顶的布局可能不完全有效:P
你显然可以把控件和重量放在你想要的位置,但从你的问题我假设这是你想要的预期行为