Android single-row gridview horizontal sliding implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.