Android studio tablerow 许多按钮
Android studio tablerow many buttons
问题 - 我想将 12 个按钮添加到我的 table 行(Android 工作室),但按钮宽度永远不会小到足以容纳所有按钮。我只能在垂直视图中放置 3 个按钮。
问题 - 是否有适合它们的合适方法?按钮文本将是整数,因此不需要很多 space.
你可以试试这个作为基础。
基本上是将 width
设置为 0DP
然后使用 weight
用于在TableRow
.
内分配
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<Button
android:width="0dp"
android:layout_weight="1"
android:text="1"/>
<Button
android:width="0dp"
android:layout_weight="1"
android:text="2"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>
我只设置了前 2 个文本。
不过您可能对文字的大小有疑问。
问题 - 我想将 12 个按钮添加到我的 table 行(Android 工作室),但按钮宽度永远不会小到足以容纳所有按钮。我只能在垂直视图中放置 3 个按钮。
问题 - 是否有适合它们的合适方法?按钮文本将是整数,因此不需要很多 space.
你可以试试这个作为基础。
基本上是将 width
设置为 0DP
然后使用 weight
用于在TableRow
.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<Button
android:width="0dp"
android:layout_weight="1"
android:text="1"/>
<Button
android:width="0dp"
android:layout_weight="1"
android:text="2"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
<Button
android:width="0dp"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>
我只设置了前 2 个文本。
不过您可能对文字的大小有疑问。