如何在不考虑android视图的情况下保持表列的大小相同

如何在不考虑android视图的情况下保持表列的大小相同,android,Android,我在button click事件中添加了一个表行。我的行有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="ma

我在button click事件中添加了一个表行。我的行有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>


提前感谢

如果微调器正在增长以匹配所选值,则您很可能已将
布局宽度
设置为
包裹内容

听起来你应该使用更像的东西来正确使用水平空间

编辑: 如果视图太大,我看不出它会滚动到哪里。听起来您应该使用or而不是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


显然,您可以放置与所需匹配的控件和权重,但从您的问题中,我假设这是您所寻求的预期行为

您可以添加布局的XML吗?,这将更容易帮助您。我已经添加了XML布局您是否以编程方式添加新行?如果是这种情况,您是否使用布局和LayoutFlater?是的,我正在获取TableLayout(id:tLayout)并使用包裹内容将行添加到其视图中微调器增长到所选项目的大小,使用布局权重,我没有获得预期的行为我已编辑答案以处理新信息,希望它能帮助Hanks Keith获得上述建议,我将尝试listview并进行更新