Recently, I made a title similar to the sliding menu bar. The grildview is used to bind the data source. To achieve horizontal sliding, The grildview displays only one row. Finally, the layout is dynamically added to the activity in the form of code.
Viewgroup. layoutparams Params = dishtype. getlayoutparams (); // dishtype, welist is the arraylist
Int dishtypes = welist. size (); Params. width = 115 * dishtypes; log. D ("Look at this width", Params. width + "" + welist. size (); dishtype. setlayoutparams (Params); // set the number of columns to the expected list length.
Dishtype. setnumcolumns (welist. Size ());
The layout file uses the horizontalscrollview control to control the left and right sliding.
<HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none" > <FrameLayout android:layout_width="match_parent" android:layout_height="80dp" > <LinearLayout android:id="@+id/liear" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <GridView android:id="@+id/dishtype" android:layout_width="match_parent" android:layout_height="80dip" android:cacheColorHint="#00000000" android:columnWidth="108dip" android:gravity="center" android:horizontalSpacing="1.0dip" android:listSelector="#00000000" android:numColumns="auto_fit" android:stretchMode="spacingWidthUniform" android:verticalSpacing="1.0dip" > </GridView> </LinearLayout> </FrameLayout> </HorizontalScrollView>