如何在android中使网格视图水平滚动而不是垂直滚动?

San*_*ush 7 grid android horizontal-scrolling

我有一个动态网格视图.意味着其内容各不相同 因此,如果项目数量增加,则会进行垂直滚动.我想把它作为水平滚动.

请为此建议一些解决方案.

小智 5

        <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>
Run Code Online (Sandbox Code Playgroud)


jai*_*rik 1

您可以尝试将其GridView放入HorizontalScrollView. 您可以尝试将固定高度设置为GridView内部HorizontalScrollView

GridView然后您可以根据您的内容动态计算列数并使用setNumColumns(int)方法来设置它。

  • 这不起作用。它只是尝试将所有项目压缩到视口中,但不会出现水平滚动 (3认同)