将GridView转换为一行

时间:2017-05-09 00:28:00

标签: java android xml gridview

我有一个网格视图,我从2列转到了一列。我想将此网格视图设置为一个滚动行,类似于Google Photos的行。这样我就可以在顶部有一排滚动的专辑,然后在顶部有单独的照片。在下面显示的图片是我所拥有的(与红色工具栏截图)与谷歌照片(我想要的,就行而言)

<GridView
    android:id="@+id/grid_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    android:clipToPadding="true"
    android:drawSelectorOnTop="true"
    android:gravity="center"
    android:horizontalSpacing="4dp"
    android:listSelector="@drawable/list_selector"
    android:numColumns="auto_fit"
    android:paddingBottom="4dp"
    android:paddingLeft="4dp"
    android:paddingRight="4dp"
    android:paddingTop="4dp"
    android:scrollbars="none"
    android:stretchMode="columnWidth"
    android:verticalSpacing="4dp" />

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用Recyclerview代替Gridview,它会为您提供结果。试试这个

RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(),3);

https://www.learn2crack.com/2016/03/grid-recyclerview-with-images-and-text.html