【问题标题】:textview in a tablelayout cannot change width表格布局中的文本视图无法更改宽度
【发布时间】:2019-07-19 02:10:54
【问题描述】:

如果您查看 ID 为“正确”的 textview 所在的 tablerow。 如果我在此 textview 的代码中放大宽度(其他一些情况也是如此),则显示中的宽度不会放大。 我不明白为什么。有人有想法吗? 这是我的代码。

如果您查看 ID 为“正确”的 textview 所在的 tablerow。 如果我在此 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】:

    我没有正确使用表格布局。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      • 2013-10-27
      • 2020-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多