【问题标题】:How can i change GridView scrolling type?如何更改 GridView 滚动类型?
【发布时间】:2018-07-06 19:24:14
【问题描述】:

我想更改 GridView 滚动样式以滚动一个部分(如使用 ViewPager)而不是一次滚动一行。 谁能告诉我在不使用任何第三方库的情况下实现此行为的最佳方法是什么?

【问题讨论】:

  • recyclerView 能满足您的需求吗?

标签: android android-gridview android-scroll


【解决方案1】:

这里有一个post,它解释了如何将 GridView 与水平滚动一起使用,据我所知,如果你想让它作为 ViewPager 工作,你正在努力实现这一目标

基本上你插入 GridView 在 Horizo​​ntalScrollView

 <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/seatLegendLayout">

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/linearLayout_gridtableLayout"
                android:layout_width="900dp"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <GridView
                    android:id="@+id/gridView1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="4dp"
                    android:columnWidth="100dp"
                    android:gravity="center"
                    android:numColumns="9"
                    android:horizontalSpacing="1dp"
                    android:scrollbarAlwaysDrawHorizontalTrack="true"
                    android:scrollbarAlwaysDrawVerticalTrack="true"
                    android:scrollbars="horizontal"
                    android:stretchMode="none"
                    android:verticalSpacing="1dp">

                </GridView>


            </LinearLayout>
        </FrameLayout>
    </HorizontalScrollView>

【讨论】:

  • 这会滚动很多列而不是每次滚动一列吗?
  • 您要水平滚动还是垂直滚动?这个不清楚
  • 我想要一个网格视图分页。我添加了一个展示我想要的视频:m.youtube.com/watch?v=jsAWx5zWo-Q(移到最后)我没有这样做,因为我想要更简单的东西而不是使用两个适配器
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多