Android GridView grid, multi-row multi-column implementation

Source: Internet
Author: User


Main activity ()


Private int [] image = {r.drawable.camera, R.drawable.wifi, R.drawable.temperature, R.drawable.lamp, R.drawable.wechat, R.drawable.mic, }; Private string[] Text = {"Webcam", "network", "Temperature and humidity", "electrical", "", "Voice"};
 //Display the GridView interfaceGridView GridView =(GridView) Findviewbyid (R.ID.GRIDVIEW1); ArrayListNewArraylist(); //use HashMap to add a picture to an array, note that it must be hashmap<string,object> type, because the image loaded in the map is the resource ID, not the picture itself//If you use Findviewbyid (r.drawable.image) to take the real picture out, put it in the map is not normal display                 for(inti = 0; I < 6; i++) {HashMap<string, object> map =NewHashmap<string, object>(); Map.put ("Image", Image[i]); Map.put ("Text", Text[i]);                Imagelist.add (map); } http://www.cnblogs.com/xiaobo-Linux/qq463431476Simpleadapter Simpleadapter=NewSimpleadapter ( This, ImageList, R.layout.items,NewString[] {"Image", "Text"},New int[] {r.id.image, r.id.title}); //set the Simpleadapter of the GridView adapter to newGridview.setadapter (Simpleadapter);


Primary XML

    <GridLayout            android:layout_width= "Match_parent"            android:layout_height= "83DP"             Android:columncount= "1"          >        </GridLayout>        <GridView            android:id = "@+id/gridview1"            android:layout_width= "Match_parent"            android:layout_height= " 53DP "            android:layout_gravity=" Left|bottom "            android:columnwidth=" 90DP "             Android:fadescrollbars= "true"             android:numcolumns= "2"            Android:stretchmode = "ColumnWidth"/>

Items.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical" > <ImageView Android:id= "@+id/image"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:paddingleft= "10px"Android:scaletype= "Fitcenter"/> <TextView Android:id= "@+id/title"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"android:padding= "5px"/></linearlayout>

Wirelessly GridView Property Daquan

android:numcolumns= "Auto_fit" //gridview the number of columns set to Auto android:columnwidth= "90DP" //width of each column, that is, the width of the item Android: Stretchmode= "ColumnWidth" //Zoom to the column width size android:verticalspacing= "10DP" //two rows between the margins android:horizontalspacing = margin between "10DP" //Two columns android:cachecolorhint= "#00000000"//Remove the default black background android:listselector= "#00000000" when dragging //Remove yellow background When selected android:scrollbars= "None" //Hide GridView scroll bar android:fadescrollbars= "true" // Set to True to automatically hide and display the scroll bar android:fastscrollenabled= "true" //gridview a fast scrolling button (at least 4 pages will be displayed) android:fadingedge= "None" //gridview fading (Fade) edge color is empty, the default value is vertical. (Can be understood as the top and bottom edge of the hint color) android:fadingedgelength= "10dip" //define the length of the fading (fade) edge android:stackfrombottom= "true" // When set to True, the list you make is displayed at the bottom of your list android:transcriptmode= "Alwaysscroll"//When you dynamically add data, the list will automatically scroll down to the latest entries to automatically scroll to the viewable range of Android: Drawselectorontop= "false" //Click on a record, the color will be the background color after the record, the text of the content is visible (default is False)

Android GridView grid, multi-row multi-column 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.