将 4 android 按钮的高度设置为 4 的最大值
Setting the height of 4 android button to the max of the 4
我有一个片段,其中显示了 4 个按钮,在这些按钮中我显示了一些从我的 sqlite 数据库中获取的文本,单击任何按钮后我通过获取其他按钮来刷新按钮上的文本来自数据库的文本。
我想要的是调整按钮的大小并将每个按钮的高度设置为按钮新大小的最大值(高度将取决于按钮中显示的文本的长度)。
我该如何执行?
开球示例:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
</LinearLayout>
更多信息 - layout_weight。
将所有 4 个按钮置于线性布局中,其中 orientation="vertical"
并分别给它们一个 layout_weight="1"
和一个 layout_height="0dp"
。这将为您提供具有相同高度的每个按钮。您可以通过调整线性布局的高度来管理整体高度。线性 Labour 的高度必须足够大以包含按钮
我有一个片段,其中显示了 4 个按钮,在这些按钮中我显示了一些从我的 sqlite 数据库中获取的文本,单击任何按钮后我通过获取其他按钮来刷新按钮上的文本来自数据库的文本。 我想要的是调整按钮的大小并将每个按钮的高度设置为按钮新大小的最大值(高度将取决于按钮中显示的文本的长度)。 我该如何执行?
开球示例:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
</LinearLayout>
更多信息 - layout_weight。
将所有 4 个按钮置于线性布局中,其中 orientation="vertical"
并分别给它们一个 layout_weight="1"
和一个 layout_height="0dp"
。这将为您提供具有相同高度的每个按钮。您可以通过调整线性布局的高度来管理整体高度。线性 Labour 的高度必须足够大以包含按钮