<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