У меня динамический вид сетки. Значит, его содержание меняется. Итак, если количество элементов увеличивается, это делает вертикальную прокрутку. Я хочу сделать его горизонтальным прокруткой.
Пожалуйста, предложите некоторое решение для этого.
Вы можете попробовать поставить GridView
в HorizontalScrollView
. Вы можете попытаться установить фиксированную высоту в GridView
внутри HorizontalScrollView
.
Затем вы можете динамически вычислять количество столбцов GridView
на основе вашего контента и использовать setNumColumns(int)
для его установки.
Вы можете использовать стороннюю библиотеку с двухсторонней сеткой . Он отлично работает для горизонтальной прокрутки, или вы можете использовать RecyclerView
<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>
1<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>
1<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>
Вы можете использовать мою логику, чтобы посмотреть на это: