我有一個recyclerView
與gridManagerLayout
這樣的:我可以在Android的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()寬= THE_WIDTH。
它看起來像黃線是在自己的位置,不知道爲什麼其他人的偏移
這是圖像
<?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它們之間的空間
<?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"/>
上傳您既XML文件太 –