GridView-demo

2020-06-10  本文已影响0人  100个大西瓜

<GridView xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/gridView"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:columnWidth="@dimen/image_thumbnail_size"

    android:horizontalSpacing="@dimen/image_thumbnail_spacing"

    android:numColumns="auto_fit"

    android:stretchMode="columnWidth"

    android:verticalSpacing="@dimen/image_thumbnail_spacing">

</GridView>

让GridView 每一行的个数自适应,需要设置每一列的宽度为固定大小,

即  android:columnWidth="@dimen/image_thumbnail_size",

然后 设置 android:numColumns="auto_fit" ,即可自适应。

其中 android:stretchMode="columnWidth"的作用是:缩放与列宽大小同步

参考自链接

上一篇 下一篇

猜你喜欢

热点阅读