更改第一个 GridView 列的大小
Change the size of the first GridView column
我正在努力使我的 GridView 的第一列比其他四列宽一点:
如您在屏幕截图中所见,第一列不够宽,无法在没有换行符的情况下显示整个日期。由于其他四列还剩下一些 space,我想缩小它们并给第一列多一点宽度。
目前,我正在使用带有 simple_list_item_1 的 ArrayAdapter 并实现我当前的结果。
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, values);
testView.setAdapter(adapter);
我的 GridView XML 看起来像这样:
<GridView
android:id="@+id/testView"
android:background="#eee"
android:numColumns="5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="0dp"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="2dp"
app:layout_constraintTop_toBottomOf="@+id/button3"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp" />
如何合理解决?
编辑:
我不想像可能的重复项那样更改所有列的大小。我只想更改第一个的大小。
利用 Span Size 获得所需的列大小。
GridLayoutManager manager = new GridLayoutManager(this, 10); // 3 cols of 3 + 1 col of 1
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position % 4 == 3)
return 1; // Fourth column is 1x
else
return 3; // Remaining columns are 3x
}
});
recyclerView.setLayoutManager(manager);
这只是一个使用span的例子,并不是你的场景的解决方案。
希望对您有所帮助。
我正在努力使我的 GridView 的第一列比其他四列宽一点:
如您在屏幕截图中所见,第一列不够宽,无法在没有换行符的情况下显示整个日期。由于其他四列还剩下一些 space,我想缩小它们并给第一列多一点宽度。
目前,我正在使用带有 simple_list_item_1 的 ArrayAdapter 并实现我当前的结果。
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, values);
testView.setAdapter(adapter);
我的 GridView XML 看起来像这样:
<GridView
android:id="@+id/testView"
android:background="#eee"
android:numColumns="5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="0dp"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="2dp"
app:layout_constraintTop_toBottomOf="@+id/button3"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp" />
如何合理解决?
编辑: 我不想像可能的重复项那样更改所有列的大小。我只想更改第一个的大小。
利用 Span Size 获得所需的列大小。
GridLayoutManager manager = new GridLayoutManager(this, 10); // 3 cols of 3 + 1 col of 1
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position % 4 == 3)
return 1; // Fourth column is 1x
else
return 3; // Remaining columns are 3x
}
});
recyclerView.setLayoutManager(manager);
这只是一个使用span的例子,并不是你的场景的解决方案。
希望对您有所帮助。