【发布时间】:2016-09-24 07:03:37
【问题描述】:
我有一个recyclerView 和一个gridManagerLayout,如下所示:
GridLayoutManager manager = new GridLayoutManager(Main.this, 10);
manager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(manager);
如您所见,第 0、2、4、6 和 8 列需要小于其他列。
我尝试过manager.setSpanSizeLookup(spanSizeLookup),但我不想更改layout manager 的spanCount。
我通过调用在构造函数中设置每个支架的宽度 itemView.getLayoutParams().width = THE_WIDTH;
好像黄线在他们的位置,不知道为什么其他人有偏移
这是图像的 XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:layout_above="@+id/text"
android:scaleType="centerCrop"/>
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Category name"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="#7f007f"/>
</RelativeLayout>
这是它们之间空间的xml
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="25dp"
android:layout_height="match_parent"
android:background="#ffff00"/>
【问题讨论】:
标签: android android-recyclerview gridlayoutmanager