Throughout the current application, the nine Gongge is a very common layout method. Many of the best mobile apps have adopted this layout. The following is the implementation of the nine Gongge layout in Android and we do a simple introduction.
First in the layout of the Youxi.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
>
<textview
Android:layout_width= "50DP"
android:layout_height= "45DP"
android:gravity= "center"
Android:id= "@+id/textview"
android:background= "@drawable/sanguosss"
/>
</RelativeLayout>
And then the layout of the Gridview.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:gravity= "Center"
android:background= "@drawable/biaoge"
>
<gridview
Android:layout_width= "200DP"
android:layout_height= "400DP"
Android:numcolumns= "5"
Android:id= "@+id/gridview"
Android:horizontalspacing= "0DP"
Android:verticalspacing= "0DP"
/>
<!--android:layout_margintop= "5DP"-
</LinearLayout>
Finally, the content of Adapter.java.
Package cn.zs.service;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import CN.ZS.LIANLIANKAN.R;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.GridView;
Import Android.widget.SimpleAdapter;
public class Youxi extends Activity {
Private string[] text={"Ah", "put", "Ah", "put", "Ah", "put", "put", "Ah",
"Ah", "put", "Ah", "put", "Ah", "put", "Ah", "put", "Ah", "put", "Ah", "put", "Ah", "put",
"Put", "Ah", "put", "Ah", "put", "Ah", "put", "Ah", "put", "ah", "ah", "put", "ah", "ah",
"Put", "Ah", "put", "Ah"};
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.gridview);
GridView gridview= (GridView) Findviewbyid (R.id.gridview);
Listfor (int i=0;i<text.length;i++) {
Hashmap<string, object> item=new hashmap<string, object> ();
Item.put ("name", Text[i]);
Data.add (item);
}
Simpleadapter simpleadapter=new Simpleadapter (Getapplicationcontext (), data, R.layout.youxi, new String[]{"name"}, New Int[]{r.id.textview});
Gridview.setadapter (Simpleadapter);
}
}
Android in nine Gongge layouts with GridView