The first is two XML interfaces:
<?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:o rientation= "vertical" > <gridview android:id= "@+id/mygridview" android:layout_alignparenttop= "True" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android: Stretchmode= "ColumnWidth" android:numcolumns= "3"/></linearlayout>
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:orientation=" vertical " android:layout_width=" match_parent " android:layout_height= "Match_parent" > <imageview android:id= "@+id/itemimageview" android:layout_width= "Wrap_ Content " android:layout_height=" wrap_content " android:paddingleft=" 10DP " android:layout_gravity=" Center "/> <textview android:id=" @+id/itemtextview " android:layout_width=" Fill_parent " android:layout_height= "wrap_content" android:gravity= "center"/></linearlayout>
Then the Java implementation Program:
1 package com.example.zhoushasha.myapplication; 2 3 Import android.support.v7.app.AppCompatActivity; 4 Import Android.os.Bundle; 5 Import Android.view.View; 6 Import Android.view.Window; 7 Import Android.view.WindowManager; 8 Import Android.widget.AdapterView; 9 Import android.widget.gridview;10 Import android.widget.simpleadapter;11 import android.widget.toast;12 Import JAVA.UTIL.ARRAYLIST;14 Import java.util.hashmap;15 Import java.util.list;16 public class Mainactivity extends appcompatactivity {private GridView mgridview;19 int[] imageres = {R.DRAWABLE.TU1, r.drawable . tu2,23 r.drawable.tu3,r.drawable.ty4,r.drawable.tu5,r.drawable.tu6,r.drawable.tu7,r.drawable.tu8,r.drawable.t U9};24 string[] itemname = {"Figure 1", "Figure 2", "Figure 3", "Figure 4", "Figure 5", 28 29 "Figure 6", "Figure 7", "Figure 8", "Figure 9" };30 @Override32 public void onCreate (Bundle savedinstancestate) {super.oncreate (Savedinstan Cestate); 36Setcontentview (R.layout.activity_main), Panax notoginseng Mgridview = (GridView) Findviewbyid (R.id.mygridview); 41 42 list Using the GridView and Simpleadapter to implement the common nine of the phone interface