【发布时间】:2021-11-22 04:22:54
【问题描述】:
我使用带有 gridLayoutManager 的 recyclerView 作为其布局管理器来显示 cardViews,但我不知道为什么它有这些右边距,尽管我在 recyclerView 和 cardView 中都没有给出任何边距
回收站查看代码
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/constraintLayoutTop"
app:layout_constraintVertical_weight="1" />
卡片查看代码
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com
/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardView1"
android:layout_width="@dimen/_146sdp"
android:layout_height="@dimen/_175sdp"
app:cardCornerRadius="@dimen/_20sdp"
app:cardElevation="0dp"
app:cardMaxElevation="0dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:strokeColor="@android:color/darker_gray"
app:strokeWidth="@dimen/_1sdp">
网格布局管理器
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),2,GridLayoutManager.VERTICAL,false);
mRecyclerView.setLayoutManager(gridLayoutManager);
【问题讨论】:
-
您正在硬编码卡片视图的宽度和高度的大小。 GridLayout 是在网格中定位视图,但没有给出在哪里做的指示。所以它只是左对齐,但由于卡片的大小是硬编码的,所以剩下的任何空间都很好......没有使用。
标签: android android-recyclerview android-cardview gridlayoutmanager