第一步,布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".JokeTabHostActivity"
android:orientation="vertical"
> <GridView
android:id="@+id/GridView"
android:listSelector="@android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:numColumns="auto_fit"
android:layout_marginTop="10dp"
android:stretchMode="columnWidth">
</GridView> </LinearLayout>

第二步,在你的activity  中调用初始化Grid

GridView gridview = (GridView) findViewById(R.id.GridView);
ArrayList<HashMap<String, Object>> meumList = new ArrayList<HashMap<String, Object>>();
for (int i = 1; i < 4; i++) {
HashMap<String, Object> map = new HashMap<String, Object>();
if (i == 1) {
map.put("ItemImage", R.drawable.a1);
map.put("ItemText", "文章精选");
} else if (i == 2) {
map.put("ItemImage", R.drawable.a2);
map.put("ItemText", "幽默笑话");
} else {
map.put("ItemImage", R.drawable.a5);
map.put("ItemText", "期待很多其它");
} meumList.add(map);
} SimpleAdapter saItem = new SimpleAdapter(this, meumList, // 数据源
R.layout.item, // xml实现
new String[] { "ItemImage", "ItemText" }, // 相应map的Key
new int[] { R.id.ItemImage, R.id.ItemText }); // 相应R的Id
// //加入Item到网格中
gridview.setAdapter(saItem); // 加入点击事件
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@SuppressWarnings("static-access")
public void onItemClick(AdapterView<? > arg0, View arg1, int arg2,
long arg3) {
int index = arg2 + 1;// id是从0開始的,所以须要+1
if (index == 1) { Intent intent = new Intent();
intent.setClass(MainActivity.this,
CloseTabHostActivity.class);
startActivity(intent); }
if (index == 2) {
Intent intent = new Intent();
intent.setClass(MainActivity.this,
XListViewActivity.class);
startActivity(intent);
//showInfo("正在努力码代码中。。。 ");
// finish();//停止当前的Activity,假设不写,则按返回键会跳转回原来的Activity
}
if (index == 3) {
showInfo("期待你的建议,好建议请Q 649175826");
}
}
});

版权声明:本文博主原创文章,博客,未经同意不得转载。

【Android】九宫格实现的更多相关文章

  1. Android九宫格界面实现点击每个格点击跳转界面

    刚开始有个任务就是做一个九宫格界面,后来有个任务就是实现点击每个格并跳转界面实现每个格的功能.下面我就介绍一下我是如何实现该功能的 首先写一下我的想法是: 登录成功后显示一个九宫格界面,每个九宫格的每 ...

  2. Android九宫格图片(9.png)的讲解与制作

    刚开始学习Android的时候,会见到res/drawable的几个文件里面有*.9.png格式命名的图片文件.起初以为这只是Android素材的一些特殊命名,其实不是.它是能实现图片素材拉伸.收缩不 ...

  3. Android 九宫格密码锁进入程序

    设置九宫格密码锁进入程序,设置,重置,取消等,安卓巴士地址http://www.apkbus.com/forum.php?mod=viewthread&tid=182620&extra ...

  4. IOS仿Android九宫格解锁效果[转]

    原理很简单,监听view中touch的一系列事件,当判定手指位置在某个按钮附近的时候则判断此按钮选中,并画出线. 效果图如下: 你可以在NineGridUnlockView.m文件中方法 touche ...

  5. android 九宫格(16宫格)控件

    public class NineRectView extends ViewGroup { private Context ctx; private int wSize,hSize,row,colum ...

  6. Android九宫格解锁有多少种姿势

    参考知乎:知乎.

  7. Android开源项目库汇总

    最近做了一个Android开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. 抽 ...

  8. GitHub上受欢迎的Android UI Library

    GitHub上受欢迎的Android UI Library 内容 抽屉菜单 ListView WebView SwitchButton 按钮 点赞按钮 进度条 TabLayout 图标 下拉刷新 Vi ...

  9. Android UI相关开源项目库汇总

    最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...

  10. GitHub 上受欢迎的 Android UI Library 整理二

    通知 https://github.com/Tapadoo/Alerter ★2528 - 克服Toast和Snackbar的限制https://github.com/wenmingvs/Notify ...

随机推荐

  1. InnoDB行格式(compact,redundant)对照

    InnoDB行格式分两种格式(COMPACT,redundant)默觉得COMPACT compact的存储格式为 首部为一个非NULL的变长字段长度列表,并且是依照列的顺序逆序放置的,当列的长度小于 ...

  2. jQuery来源学习笔记:整体结构

    1.1.由于调用一个匿名函数: (function( window, undefined ) { // jquery code })(window); 这是一个自调用匿名函数,第一个括号内是一个匿名函 ...

  3. Oracle Instanc Client安装命令工具

    条件 1.Linux RHEL 6.X X86_64操作系统 2.从安装Oracleserver的server此次收购Oracle相关文件(同OS) 软件下载 从Oracle包: 1)  instan ...

  4. Python 显示LinkedIn用户作业

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-18 @author: guaguastd @name: j ...

  5. HDU 1698 Just a Hook (段树更新间隔)

    Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible thing for m ...

  6. linux 下一个 osw先从操作系统和标准脚本主动发起

    linux 下一个 osw与操作系统的引导和启动标准的脚本.osw它指的是--os watcher,这是一个显示器os这些指标shell脚本.osw监测数据一般使用oracle技能评估os资源的使用, ...

  7. HDU 3415 Max Sum of Max-K-sub-sequence(单调队列)

    转载请注明出处:http://blog.csdn.net/u012860063 Max Sum of Max-K-sub-sequence Time Limit: 2000/1000 MS (Java ...

  8. 《Javascript权威指南》13号学习笔记:使用日期和时间

    一.创Date示例 1.Date类的方法和属性是非常不静,故,申请书Date属性和方法之前.必须创建Date类的实例. var date = new Date();  //以当前日期和时间创建实例. ...

  9. RH253读书笔记(4)-Lab 4 The Domain Name System

    Lab 4 The Domain Name System Goal: To install and configure a DNS server System Setup: Throughout th ...

  10. 开源远程控制RealVNC源代码中的通讯协议RFB(远程帧缓冲)(转)

    在网上流传的gh0st3.6源代码中,远程桌面总是存在CPU占用率高和画面更新不及时等问题.于是想到了著名的开源远程控制RealVNC  它采用了远程帧缓存的协议(Remote Frame buffe ...