我使用了一个有两个按钮的柔性布局。我之所以使用flex布局,是因为按钮的文本可能会增加,如果发生这种情况,我希望按钮垂直堆叠。
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flexWrap="wrap"
>
<Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
app:layout_flexGrow="1"
style="?attr/materialButtonOutlinedStyle"
/>
<Button
android:id="@+id/apply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apply"
app:layout_flexGrow="1"
/>
</com.google.android.flexbox.FlexboxLayout>
我目前面临的问题是:
当两个按钮水平地显示在一行时,
如果按钮是垂直堆叠的,
发布于 2022-06-10 05:40:29
对于问题1:我为柔性盒布局添加了左边的填充,并为两个按钮添加了右填充。因此,即使他们是水平堆叠,他们将有相同的左和右填充。
对于问题2:只需使用app:flexWrap="wrap_reverse"
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
app:flexWrap="wrap_reverse">
<Button
android:id="@+id/clear"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="Clear"
app:layout_flexGrow="1"
/>
<Button
android:id="@+id/apply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="Apply"
app:layout_flexGrow="1" />
</com.google.android.flexbox.FlexboxLayout>
https://stackoverflow.com/questions/72555642
复制相似问题