Gridview Android implements horizontal scrolling of multiple columns in a single row, and gridview android

Source: Internet
Author: User

Gridview Android implements horizontal scrolling of multiple columns in a single row, and gridview android

  <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" />                 </LinearLayout>             </HorizontalScrollView>        </GridLayout>

Specify the width of LinearLayout to change the length and width of your GridView. If its length exceeds the screen, a horizontal scroll bar is automatically added.

 

Private int [] icon = {R. drawable. camera, R. drawable. wifi, R. drawable. temperature, R. drawable. lamp, R. drawable. wechat, R. drawable. mic,}; private String [] iconName = {"camera", "network", "Temperature and Humidity", "electric appliance", "", "Voice"}; private GridView gview; private List <Map <String, Object> data_list; private SimpleAdapter sim_adapter; protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState );
// Gridview data adapter gview = (GridView) findViewById (R. id. gridview1); // create a List data_list = new ArrayList <Map <String, Object> (); // obtain data getData (); // create an adapter String [] from = {"image", "text"}; int [] to = {R. id. image, R. id. title}; sim_adapter = new SimpleAdapter (this, data_list, R. layout. items, from, to); // configure the adapter gview. setAdapter (sim_adapter); http://www.cnblogs.com/xiaobo-Linux/ qq463431476} public List <Map <String, Object> getData () {// The length of cion and iconName is the same, either of them can be for (int I = 0; I <icon. length; I ++) {Map <String, Object> map = new HashMap <String, Object> (); map. put ("image", icon [I]); map. put ("text", iconName [I]); data_list.add (map);} return data_list ;}

 

Fragment:

Initialize data in oncreate, initialize the gridview and bind the adapter in oncreateview
Public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {// TODO Auto-generated method stub View = inflater. inflate (R. layout. gridview, container, false); gridview = (GridView) view. findViewById (R. id. gridview1); // create a List data_list = new ArrayList <Map <String, Object> ();

// Http://www.cnblogs.com/xiaobo-Linux/ qq463431476 // getData (); // new adapter String [] from = {"image", "text"}; int [] to = {R. id. image, R. id. title}; sim_adapter = new SimpleAdapter (getActivity (), data_list, R. layout. items, from, to); // configure the adapter gridview. setAdapter (sim_adapter); return view ;}

 

Public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState);} // http://www.cnblogs.com/xiaobo-Linux/ qq463431476 public List <Map <String, Object> getData () {// The length of cion and iconName is the same, either of them can be for (int I = 0; I <icon. length; I ++) {Map <String, Object> map = new HashMap <String, Object> (); map. put ("image", icon [I]); map. put ("text", iconName [I]); data_list.add (map);} return data_list ;}

 

 

Related Article

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.