gpt4 book ai didi

android - tablelayout 中的 textview 不能改变宽度

转载 作者:行者123 更新时间:2023-11-30 05:04:03 29 4
gpt4 key购买 nike

如果您查看表格行,其中有 ID 为“correct”的 TextView 。如果我在这个 textview 的代码中扩大宽度(其他一些也是如此),则显示中的宽度不会扩大。我不明白为什么。有人有想法吗?这是我的代码。

如果您查看表格行,其中有 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>

最佳答案

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

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

关于android - tablelayout 中的 textview 不能改变宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54870166/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com