垂直回收器视图中的列未居中
Posted
技术标签:
【中文标题】垂直回收器视图中的列未居中【英文标题】:Columns in the vertical recycler view are not centered 【发布时间】:2020-06-17 05:19:57 【问题描述】:左右,我的柱子和屏幕边缘之间的距离不同。但我想看到他们一样。
当前状态
Item.xml
<com.google.android.material.card.MaterialCardView
android:layout_
android:layout_>
...
</com.google.android.material.card.MaterialCardView>
Layout.xml
</LinearLayout>
android:layout_
android:layout_>
...
<androidx.recyclerview.widget.RecyclerView
android:layout_
android:layout_
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="4"
.../>
</LinearLayout>
【问题讨论】:
【参考方案1】:我通过添加一个 match_parent 宽度的根元素并设置嵌入视图的 center_horizontal 解决了这个问题。
Item.xml
<FrameLayout
android:layout_
android:layout_>
<com.google.android.material.card.MaterialCardView
android:layout_
android:layout_
android:layout_gravity="center_horizontal">
...
</com.google.android.material.card.MaterialCardView>
</FrameLayout>
结果:
【讨论】:
以上是关于垂直回收器视图中的列未居中的主要内容,如果未能解决你的问题,请参考以下文章
Vertical RecyclerView 中的 Horizontal RecyclerViews 丢失位置/状态