Android九宫格
Android九宫格
显示九宫格需要用GridView , 要显示每个格子中的视图有两种方式,第一种方式是做成xml文件,再将xml文件做成视图。第二种方式就是在代码中构建出这样一种布局,这里采用第一种方式来实现:
效果:
GridView:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:Android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <!-- id gv_all
- 宽高都是填充父窗体
- numcolums 为3
- 水平控件的距离 10px
- 垂直距离是10px
- gridview 离底部58px
- 离顶部28px
- 离左边5px
- 离右边5px
- -->
- <GridView
- android:id="@+id/gv_all"
- android:layout_height="fill_parent"
- android:layout_width="fill_parent"
- android:numColumns="3"
- android:horizontalSpacing="10px"
- android:verticalSpacing="10px"
- android:layout_marginBottom="58px"
- android:layout_marginTop="28px"
- android:layout_marginLeft="5px"
- android:layout_marginRight="5px"
- ></GridView>
- </RelativeLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="90px"
- android:layout_height="90px">
- <ImageView
- android:layout_width="64px"
- android:layout_height="64px"
- android:layout_gravity="center_horizontal"
- android:id="@+id/main_gv_iv"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:textSize="16px"
- android:textColor="#FFF"
- android:id="@+id/main_gv_tv"
- />
- </LinearLayout>
|
评论暂时关闭