GridView Android implements single-row multi-row horizontal scrolling

Source: Internet
Author: User

<GridLayout android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:columncount= "1" > <Horizontalscrollview android:layout_width= "Match_parent"Android:layout_height= "88DP"Android:layout_column= "0"android:layout_gravity= "Left|bottom"Android:layout_row= "0" > <LinearLayout Android:id= "@+id/linearlayout_gridtablelayout"Android:layout_width= "1000DP"Android:layout_height= "79DP"android:orientation= "Horizontal" > <GridView Android:id= "@+id/gridview1"Android:layout_width= "600DP"Android:layout_height= "Match_parent"Android:background= "#ffffff"Android:columnwidth= "100DP"android:gravity= "Center"android:horizontalspacing= "1DP"Android:numcolumns= "6"Android:scrollbaralwaysdrawhorizontaltrack= "true"Android:scrollbaralwaysdrawverticaltrack= "true"Android:scrollbars= "Horizontal|vertical"android:verticalspacing= "1DP"/>http://www.cnblogs.com/xiaobo-Linux/qq463431476</LinearLayout> </HorizontalScrollView> </GridLayout>

Specifying the width of the linearlayout will enable you to change the length and width of your GridView, and automatically add a horizontal scrollbar if it is longer than the screen.

 Private int[] icon ={r.drawable.camera, R.drawable.wifi, R.drawable.temperature, R.drawable.lamp, R.drawable.wechat, R.drawab    Le.mic,}; PrivateString[] Iconname = {"Webcam", "network", "Temperature and humidity", "electrical", "", "voice" }; PrivateGridView Gview; PrivateList<map<string, object>>data_list; PrivateSimpleadapter Sim_adapter;protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //GridView Data AdapterGview =(GridView) Findviewbyid (R.ID.GRIDVIEW1); //New ListData_list =NewArraylist<map<string, object>>(); //Get DataGetData (); //New AdapterString [] from ={"image", "text"}; int[] to ={r.id.image,r.id.title}; Sim_adapter=NewSimpleadapter ( This, Data_list, R.layout.items, from, to); //Configure the adapterGview.setadapter (Sim_adapter); http://www.cnblogs.com/xiaobo-Linux/qq463431476  } PublicList<map<string, object>>GetData () {//the lengths of Cion and Iconname are the same, and any one of them can be             for(inti=0;i<icon.length;i++) {Map<string, object> map =NewHashmap<string, object>(); Map.put ("Image", Icon[i]); Map.put ("Text", Iconname[i]);            Data_list.add (map); }                            returndata_list; }        

GridView Android implements single-row multi-row horizontal scrolling

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.