Android single-row gridview horizontal sliding implementation
First rewrite the next GridView
Horizontalgridview.java
Public class horizontalgridview extends GridView { Public Horizontalgridview(context context, AttributeSet attrs) {Super(context, attrs); } Public Horizontalgridview(Context context) {Super(context); } Public Horizontalgridview(context context, AttributeSet attrs,intDefstyle) {Super(Context, attrs, Defstyle); }@Override Public void onmeasure(intWidthmeasurespec,intHEIGHTMEASURESPEC) {intChildCount = Getchildcount ();intChildwidth = commonutil.dip2px ( the);intChildheight = commonutil.dip2px ( -);intlastpadding = commonutil.dip2px (Ten);intExpandspec = Measurespec.makemeasurespec (Integer.max_value >>2, measurespec.at_most);Super. Onmeasure (Expandspec, Heightmeasurespec);//Set the width of the GridViewSetmeasureddimension (ChildCount * childwidth + lastpadding, childheight); }}
Then there is the GridView layout file
<horizontalscrollviewandroid:layout_width="Match_parent"android:layout_ Height="Wrap_content"android:scrollbars="None"> <the package name of your project. Horizontalgridview Android:id="@+id/gv_my_game" Android:layout_width="Wrap_content" Android:layout_height="Wrap_content" Android:columnwidth="88DP" Android:divider="@null" android:horizontalspacing="0DP" Android:listselector="@drawable/item_bg" Android:numcolumns="Auto_fit" Android:scrollbars="None"/> </horizontalscrollview>
Then you can use a single line of horizontal sliding gridview.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android single-row gridview horizontal sliding implementation