tablelayout中的textview无法更改宽度

问题描述 投票:1回答:1

如果你看一下tablerow里面有ID为'correct'的textview。如果我在此textview的代码中放大宽度(也是其他一些的情况),则显示中的宽度不会放大。我不明白为什么。有人有想法吗?这是我的代码。

如果你看一下tablerow里面有ID为'correct'的textview。如果我在此textview的代码中放大宽度(也是其他一些的情况),则显示中的宽度不会放大。我不明白为什么。有人有想法吗?这是我的代码。

谢谢

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="10dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="10dp"
        android:shrinkColumns="*">
        <TableRow
            android:layout_height="30dp">
            <View
                android:id="@+id/viewEmpty5"
                android:background="@android:color/transparent"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_span="1"/>
            <TextView
                android:id="@+id/A"
                android:layout_width="0dp"
                android:layout_weight="0.3"
                android:text="@string/btn1"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"
                android:background="@color/colorPrimary"/>
            <TextView
                android:id="@+id/B"
                android:layout_width="0dp"
                android:layout_weight="0.3"
                android:background="@color/colorPrimary"
                android:text="@string/btn1"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"/>
            <TextView
                android:id="@+id/C"
                android:layout_width="0dp"
                android:layout_weight="0.3"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"
                android:background="@color/colorPrimary"
                android:text="@string/btn1"/>
            <View
                android:id="@+id/viewEmpty6"
                android:background="@android:color/transparent"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_span="1"/>
        </TableRow>
        <TableRow>
            <View
                android:id="@+id/viewEmpty1"
                android:layout_width="20dp"

                android:background="@android:color/transparent"
                android:layout_span="5"
                android:layout_height="30dp"/>
        </TableRow>
        <TableRow>
            <View
                android:id="@+id/viewEmpty7"
                android:background="@android:color/transparent"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_span="2"/>
            <TextView
                android:id="@+id/equalsign"
                android:layout_width="0dp"
                android:layout_weight="0.3"
                android:layout_height="30dp"
                android:background="@color/colorPrimary"
                android:text="@string/equalsign"
                android:layout_span="1"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"/>
            <EditText
                android:id="@+id/D"
                android:background="@color/colorPrimaryDark"
                android:layout_width="0dp"
                android:layout_weight="0.6"
                android:layout_height="30dp"
                android:hint="Is gelijk aan"
                android:layout_span="1"
                android:inputType="number"
                android:imeOptions="actionGo"/>
            <View
                android:id="@+id/viewEmpty8"
                android:background="@android:color/transparent"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_span="1"/>
        </TableRow>
        <TableRow>
            <View
                android:id="@+id/viewEmpty3"
                android:background="@android:color/transparent"
                android:layout_span="5"
                android:layout_width="30dp"
                android:layout_height="30dp"/>
        </TableRow>
        <TableRow>
            <TextView
                android:id="@+id/correct"
                android:background="@android:color/transparent"
                android:layout_width="100dp"
                android:layout_span="2"
                android:layout_height="30dp"/>
            <View
                android:id="@+id/viewEmpty2"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:background="@color/colorPrimary"
                android:layout_span="1"
                android:text="@string/btn1"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"/>
            <TextView
                android:id="@+id/incorrect"
                android:background="@android:color/transparent"
                android:layout_span="2"
                android:layout_width="30dp"
                android:layout_height="30dp"
                />
        </TableRow>
        <TableRow>
            <View
                android:id="@+id/viewEmpty4"
                android:background="@android:color/transparent"
                android:layout_span="5"
                android:layout_width="30dp"
                android:layout_height="30dp"/>
        </TableRow>
        <TableRow
            android:layout_height="30dp">
            <TextView
                android:id="@+id/verbetering"
                android:background="@android:color/transparent"
                android:layout_span="5"
                android:layout_width="match_parent"
                android:layout_height="30dp"/>
        </TableRow>
        <TableRow>
            <View
                android:id="@+id/viewEmpty9"
                android:background="@android:color/transparent"
                android:layout_height="20dp"
                android:layout_span="5"/>
        </TableRow>
        <TableRow>
            <com.google.android.gms.ads.AdView
                xmlns:ads="http://schemas.android.com/apk/res-auto"
                android:id="@+id/adView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_alignParentBottom="true"
                ads:adSize="BANNER"
                ads:adUnitId="@string/add_unit_id2"
                android:layout_span="5"/>
        </TableRow>
    </TableLayout>
</RelativeLayout>
android width tablelayout
1个回答
0
投票

我没有以正确的方式使用tablelayout。

TableLayout的子项不能指定layout_width属性。宽度始终是MATCH_PARENT。列的宽度由该列中具有最宽单元格的行定义。但是,layout_height属性可以由子项定义;默认值为ViewGroup.LayoutParams.WRAP_CONTENT。如果孩子是TableRow,那么身高总是为ViewGroup.LayoutParams.WRAP_CONTENT。 (https://developer.android.com/reference/android/widget/TableLayout

© www.soinside.com 2019 - 2024. All rights reserved.