【Android】九宫格实现
第一步,布局文件
<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】九宫格实现的更多相关文章
- Android九宫格界面实现点击每个格点击跳转界面
刚开始有个任务就是做一个九宫格界面,后来有个任务就是实现点击每个格并跳转界面实现每个格的功能.下面我就介绍一下我是如何实现该功能的 首先写一下我的想法是: 登录成功后显示一个九宫格界面,每个九宫格的每 ...
- Android九宫格图片(9.png)的讲解与制作
刚开始学习Android的时候,会见到res/drawable的几个文件里面有*.9.png格式命名的图片文件.起初以为这只是Android素材的一些特殊命名,其实不是.它是能实现图片素材拉伸.收缩不 ...
- Android 九宫格密码锁进入程序
设置九宫格密码锁进入程序,设置,重置,取消等,安卓巴士地址http://www.apkbus.com/forum.php?mod=viewthread&tid=182620&extra ...
- IOS仿Android九宫格解锁效果[转]
原理很简单,监听view中touch的一系列事件,当判定手指位置在某个按钮附近的时候则判断此按钮选中,并画出线. 效果图如下: 你可以在NineGridUnlockView.m文件中方法 touche ...
- android 九宫格(16宫格)控件
public class NineRectView extends ViewGroup { private Context ctx; private int wSize,hSize,row,colum ...
- Android九宫格解锁有多少种姿势
参考知乎:知乎.
- Android开源项目库汇总
最近做了一个Android开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. 抽 ...
- GitHub上受欢迎的Android UI Library
GitHub上受欢迎的Android UI Library 内容 抽屉菜单 ListView WebView SwitchButton 按钮 点赞按钮 进度条 TabLayout 图标 下拉刷新 Vi ...
- Android UI相关开源项目库汇总
最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...
- GitHub 上受欢迎的 Android UI Library 整理二
通知 https://github.com/Tapadoo/Alerter ★2528 - 克服Toast和Snackbar的限制https://github.com/wenmingvs/Notify ...
随机推荐
- Android.mk参数解释
-------------------- 下面对Android.mk 中经常出现的变量进行讲解 -------------------- 这些变量,你会经常在Android.mk文件中见到,下面以字表 ...
- android下调试声卡驱动之概述
在Android中音频系统使用的是ALSA系统架构.ASoC--ALSA System on Chip .是建立在标准ALSA驱动层上,为了更好地支持 嵌入式处理器和移动设备中的音频Codec的一套软 ...
- TypeScript 5 Angular 2
TypeScript 5 分钟快速入门 翻译:Angular 2 - TypeScript 5 分钟快速入门 原文地址:https://angular.io/docs/ts/latest/quicks ...
- php 两个文件之间的相对路径的计算方法
php 两个文件之间的相对路径的计算方法 比如: 文件A 的路径是 /home/web/lib/img/cache.php 文件B的路径是 /home/web/api/img/show.php 那么. ...
- jquery ui 笔记
准备: 1.下载jquery ui库:http://jqueryui.com/download/ 2.选择theme 3.建立一个良好的发展环境(mysql.netbeans) 4.创建数据库:jqu ...
- Android-管理Activity生命周期 -开始一个Activity
很多程序都是从main()方法开始启动的,和其他程序不同,android是在activity生命周期的特定状态的特定回调方法中初始化代码的.activity启动和销毁的时候都用很多回调方法. 这里将要 ...
- RedHat Linux乱码解决方案(转)
RedHat Linux中出现中文乱码主要是由于没有安装中文字体,因此解决方案主要是安装中文字体,所以 第一步,挂载安装的光盘 在虚拟机的菜单栏里,选择:VM->Settings,点击Setti ...
- mac eclipse svn subeclipse: Failed to load JavaHL Library.
Failed to load JavaHL Library. These are the errors that were encountered: no libsvnjavahl-1 in java ...
- IOS使用Jenkins持续集成
本文详细介绍了开发过程,提高效率进行IOS-Jenkins持续集成. 第二http://blog.csdn.net/monkey_cool/article/details/43270885 背景 平时 ...
- Build制作模型
#include <iostream> using namespace std; //不知道为什么事实上非常好解释的东西在网上搞的人晕头转向的,下面是我的理解. //一个基类衍生出很多详细 ...