http://blog.sina.com.cn/s/blog_8c3095e601019bpx.html
- <?xml
version="1.0" encoding="utf-8"?> - <!--主界面的布局-->
- <RelativeLayout
-
xmlns:android="http://schemas.android.com/apk/res/android" -
android:orientation="vertical" -
android:layout_width="fill_parent" -
android:layout_height="fill_parent" -
-
> -
<RelativeLayout -
android:id="@+id/MainActivityrlTwo" -
android:layout_width="fill_parent" -
android:layout_height="45dp" -
-
> -
-
</RelativeLayout> -
-
<GridView -
android:id="@+id/MainActivityGrid" -
android:layout_width="fill_parent" -
android:layout_height="wrap_content" -
android:numColumns="3" -
android:columnWidth="50dp" -
android:layout_below="@+id/MainActivityrlTwo" -
android:layout_marginTop="5dp" -
/> -
-
<RelativeLayout -
android:id="@+id/MainActivityrlThree" -
android:layout_width="fill_parent" -
android:layout_height="60dp" -
android:layout_alignParentBottom="true" -
-
> -
<TextView -
android:id="@+id/tvLineBottom" -
android:layout_width="fill_parent" -
android:layout_height="wrap_content" -
android:text="@string/line_default" -
/> -
<Button -
android:id="@+id/btmore_MainActivity" -
android:layout_alignParentRight="true" -
android:layout_alignParentBottom="true" -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:text="More" -
-
/> -
</RelativeLayout> -
- </RelativeLayout>
- <?xml
version="1.0" encoding="utf-8"?> - <!--九宫格每一格的布局-->
- <LinearLayout
-
xmlns:android="http://schemas.android.com/apk/res/android" -
android:orientation="vertical" -
android:layout_width="fill_parent" -
android:layout_height="fill_parent" -
> -
<ImageView -
android:id="@+id/MainActivityImage" -
android:layout_width="50dp" -
android:layout_height="50dp" -
android:layout_gravity="center_horizontal" -
/> -
<TextView -
android:id="@+id/MainActivityText" -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_gravity="center_horizontal" -
android:textSize="18sp" -
android:lines="1" -
android:layout_marginTop="8dp" -
/> - </LinearLayout>
-
- public
class ImageAdapter extends BaseAdapter { -
private Context context; -
-
public ImageAdapter(Context context) { -
this.context=context; -
} -
-
private Integer[] images = { -
//九宫格图片的设置 -
R.drawable.icon_1, -
R.drawable.icon_2, -
R.drawable.icon_3, -
R.drawable.icon_4, -
R.drawable.icon_5, -
R.drawable.icon_6, -
R.drawable.icon_7, -
R.drawable.icon_8, -
R.drawable.icon_9, -
}; -
-
private String[] texts = { -
//九宫格图片下方文字的设置 -
"记录支出", -
"记录收入", -
"账本管理", -
"类别管理", -
"查看图表", -
"收支对照", -
"记录心得", -
"新闻公告", -
"系统设置", -
}; -
-
//get the number -
@Override -
public int getCount() { -
return images.length; -
} -
-
@Override -
public Object getItem(int position) { -
return position; -
} -
-
//get the current selector's id number -
@Override -
public long getItemId(int position) { -
return position; -
} -
-
//create view method -
@Override -
public View getView(int position, View view, ViewGroup viewgroup) { -
ImgTextWrapper wrapper; -
if(view==null) { -
wrapper = new ImgTextWrapper(); -
LayoutInflater inflater = LayoutInflater.from(context); -
view = inflater.inflate(R.layout.item, null); -
view.setTag(wrapper); -
view.setPadding(15, 15, 15, 15); //每格的间距 -
} else { -
wrapper = (ImgTextWrapper)view.getTag(); -
} -
-
wrapper.imageView = (ImageView)view.findViewById(R.id.MainActivityImage); -
wrapper.imageView.setBackgroundResource(images[position]); -
wrapper.textView = (TextView)view.findViewById(R.id.MainActivityText); -
wrapper.textView.setText(texts[position]); -
-
return view; -
} - }
-
- class
ImgTextWrapper { -
ImageView imageView; -
TextView textView; -
- }