【发布时间】:2020-12-26 02:12:32
【问题描述】:
这是我想要实现的目标:如果按钮标题很短,则按钮的宽度应该相等,但较长的文本应该以牺牲另一个按钮为代价来拉伸相应的按钮。
这是我的布局,适用于 Fragment 或 Activity 的布局。但它没有正确显示在 AlertDialog 的自定义视图中使用
<androidx.gridlayout.widget.GridLayout
android:layout_width="match_parent"
app:columnCount="2"
app:rowCount="1"
app:alignmentMode="alignBounds"
app:useDefaultMargins="true"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
app:layout_columnWeight="1"
app:layout_gravity="fill_horizontal"
android:text="Cancel" />
<com.google.android.material.button.MaterialButton
app:layout_columnWeight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="fill_horizontal"
android:text="Very long button title" />
</androidx.gridlayout.widget.GridLayout>
这是失败的结果,显示在布局检查器中。关于如何在这种情况下使这种布局起作用的任何想法?
【问题讨论】:
标签: android android-layout android-alertdialog android-gridlayout