【发布时间】:2019-03-27 17:52:45
【问题描述】:
我有一个包含RecyclerView 的警报对话框。回收器中的每个项目都是一个简单的复选框。我需要把它画成三列。
为此,我使用 GridLayoutManager
layoutManager = GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, false)
我看到的结果是这样的
还不错。问题是我需要将每一列的宽度设置为对话框宽度的 33%。我的复选框没有任何固定宽度(以像素为单位),因为文本可能会有所不同。这是用于回收器的布局。
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="item" type="..." />
</data>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="@={item.enabled}"
android:text="@{item.name}"
android:minWidth="40dp"/>
</layout>
我的 Recycler 创建时宽度等于父级
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
任何想法如何以百分比设置宽度?
【问题讨论】:
-
您是否尝试过更改复选框大小以匹配父级?
-
是的,在这种情况下它只绘制第一列