Android UI开发第一篇——android的九宫格式实现
2014-05-13 10:38
330 查看
九宫格的实现,经验分享一下。
xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.google.android.gx5weather"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:background="@drawable/bg"
>
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/top"></ImageView>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:verticalSpacing="30dip"
android:horizontalSpacing="10dip"
android:columnWidth="90dip" //列宽
android:stretchMode="columnWidth"
android:gravity="center"
android:listSelector="@drawable/grid_selector_background"
>
</GridView>
</LinearLayout>
android:numColumns="3" //九宫格的列数 auto_fit时为自动
android:listSelector="@drawable/grid_selector_background" //九宫格的背景,可以找个圆角正方形
public class NineBox extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main_activity);
GridView gridview=(GridView)findViewById(R.id.gridview);
ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
for(int i=1;i<10;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
if(i==1){
map.put("ItemImage", R.drawable.g11);
map.put("ItemText", getResources().getString(R.string.gridview1));
}
if(i==2){
map.put("ItemImage", R.drawable.g12);
map.put("ItemText", getResources().getString(R.string.gridview2));
}
if(i==3){
map.put("ItemImage", R.drawable.g13);
map.put("ItemText", getResources().getString(R.string.gridview3));
}
if(i==4){
map.put("ItemImage", R.drawable.g14);
map.put("ItemText", getResources().getString(R.string.gridview4));
}
if(i==5){
map.put("ItemImage", R.drawable.g15);
map.put("ItemText", getResources().getString(R.string.gridview5));
}
if(i==6){
map.put("ItemImage", R.drawable.g16);
map.put("ItemText", getResources().getString(R.string.gridview6));
}
if(i==7){
map.put("ItemImage", R.drawable.g17);
map.put("ItemText", getResources().getString(R.string.gridview7));
}
if(i==8){
map.put("ItemImage", R.drawable.g18);
map.put("ItemText", getResources().getString(R.string.gridview8));
}
if(i==9){
map.put("ItemImage", R.drawable.g1
xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.google.android.gx5weather"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:background="@drawable/bg"
>
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/top"></ImageView>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:verticalSpacing="30dip"
android:horizontalSpacing="10dip"
android:columnWidth="90dip" //列宽
android:stretchMode="columnWidth"
android:gravity="center"
android:listSelector="@drawable/grid_selector_background"
>
</GridView>
</LinearLayout>
android:numColumns="3" //九宫格的列数 auto_fit时为自动
android:listSelector="@drawable/grid_selector_background" //九宫格的背景,可以找个圆角正方形
public class NineBox extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main_activity);
GridView gridview=(GridView)findViewById(R.id.gridview);
ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
for(int i=1;i<10;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
if(i==1){
map.put("ItemImage", R.drawable.g11);
map.put("ItemText", getResources().getString(R.string.gridview1));
}
if(i==2){
map.put("ItemImage", R.drawable.g12);
map.put("ItemText", getResources().getString(R.string.gridview2));
}
if(i==3){
map.put("ItemImage", R.drawable.g13);
map.put("ItemText", getResources().getString(R.string.gridview3));
}
if(i==4){
map.put("ItemImage", R.drawable.g14);
map.put("ItemText", getResources().getString(R.string.gridview4));
}
if(i==5){
map.put("ItemImage", R.drawable.g15);
map.put("ItemText", getResources().getString(R.string.gridview5));
}
if(i==6){
map.put("ItemImage", R.drawable.g16);
map.put("ItemText", getResources().getString(R.string.gridview6));
}
if(i==7){
map.put("ItemImage", R.drawable.g17);
map.put("ItemText", getResources().getString(R.string.gridview7));
}
if(i==8){
map.put("ItemImage", R.drawable.g18);
map.put("ItemText", getResources().getString(R.string.gridview8));
}
if(i==9){
map.put("ItemImage", R.drawable.g1
相关文章推荐
- Android UI开发第一篇——android的九宫格式实现
- Android UI开发第一篇——android的九宫格式实现
- Android UI开发第一篇——android的九宫格式实现
- Android UI开发第一篇——android的九宫格式实现
- UI开发第一篇——android的九宫格式实现
- Android UI开发第一篇——android的九宫格式实现
- Android UI----android的九宫格式实现
- Android开发-01 九宫解锁实现
- Android UI开发第二十二篇——android 瀑布流图片实现
- android的九宫格式实现
- (Touch Android) 新浪微博Android客户端开发第一篇:Logo 页面的实现
- Android UI开发第四篇——实现像handcent sms或者chomp sms那样的气泡短信样式
- Android开发(17)-通过安卓API的Tabs3实现仿优酷tabhost效果
- 【Android应用开发详解】第01期:第三方授权认证(一)实现第三方授权登录、分享以及获取用户资料
- 【Android UI设计与开发】第18期:滑动菜单栏(三)SlidingMenu动画效果的实现 .
- Android开发必备技能之:Android中图片的三级缓存实现
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
- Android UI开发第二十篇——仿launcher的左右滑动(用ViewPager实现欢迎引导页面)
- 【Android UI设计与开发】Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- Android应用开发--MP3音乐播放器Service实现