第31讲 UI组件之 Gallery画廊控件
第31讲 UI组件之 Gallery画廊控件
1.Gallery的简介
Gallery(画廊)是一个锁定中心条目并且拥有水平滚动列表的视图,一般用来浏览图片,并且可以响应事件显示信息。Gallery只能水平显示一行,且Gallery列表中的图片会根据不同的拖动情况向左或向右移动,直到最后一张图片为止。Gallery还可以和ImageSwitcher组件结合使用来实现一个通过缩略图来浏览图片的效果。
Gallery常用的XML属性
|
属性名称 |
描述 |
|||||||||||||||||||||||||||||||||||||||
|
android:animationDuration |
设置布局变化时动画的转换所需的时间(毫秒级)。仅在动画开始时计时。该值必须是整数,比如:100。 |
|||||||||||||||||||||||||||||||||||||||
|
android:gravity |
指定在对象的X和Y轴上如何放置内容。指定一下常量中的一个或多个(使用 “|”分割)
|
|||||||||||||||||||||||||||||||||||||||
|
android:spacing |
图片之间的间距 |
|||||||||||||||||||||||||||||||||||||||
|
android:unselectedAlpha |
设置未选中的条目的透明度(Alpha)。该值必须是float类型,比如:“1.2”。 |
一、实现图片的左右滑动浏览效果。
//Gallery的使用方法类似于其余的ViewGroup控件,使用adapter进行布局。
Gallery gallery=(Gallery)findViewById(R.id.gallery1);
//设置图片适配器
gallery.setAdapter(new MyAdapter(image,this));
//image:定义整型数组 即图片源
final int[] image=new int[] {R.drawable.attack , R.drawable .boy1 , R.drawable .boy2 , R.drawable .doupo };
MyAdapter定义如下:
private class MyAdapter extends BaseAdapter{
private int[] image;
private Context context;
public MyAdapter(int[] image, Context context) {
super();
this.image = image;
this.context = context;
}
public int getCount() { return image.length; } //获取图片的个数
public Object getItem(int arg0) { return null; }
public long getItemId(int arg0) { return 0; }
public View getView(int arg0, View arg1, ViewGroup arg2) {
ImageView imageView=new ImageView(context);
imageView.setImageResource(image[arg0]); //给ImageView设置资源
return imageView;
}
}
二、实现缩略图加放大图显示
对上述程序做修改:
首先,将layout设置为上方为ImageView,下方为Gallery显示缩略图。
之后,通过设置点击Gallery时设置图片到ImageView中。
final ImageView imageView=(ImageView)findViewById(R.id.imageView1);
Gallery gallery=(Gallery) findViewById(R.id.gallery1);
//设置图片适配器
gallery.setAdapter(new MyAdapter(image,this));
//设置监听器
gallery.setOnItemClickListener(newOnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, intposition, long arg3) {
imageView.setImageResource(image[position]);
}
});
public View getView(int arg0, View arg1,ViewGroup arg2) {
ImageView imageView=new ImageView(context);
//设置布局图片120x120显示
imageView.setLayoutParams(new Gallery.LayoutParams(120, 120));
imageView.setImageResource(image[arg0]); //给ImageView设置资源
return imageView;
}
第31讲 UI组件之 Gallery画廊控件的更多相关文章
- 第32讲 UI组件之 时间日期控件DatePicker和TimePicker
第32讲 UI组件之 时间日期控件DatePicker和TimePicker 在Android中,时间日期控件相对来说还是比较丰富的.其中, DatePicker用来实现日期输入设置, Time ...
- UI组件之AdapterView及其子类(四)Gallery画廊控件使用
听说 Gallery如今已经不使用了,API使用ViewPaper取代了,以后再学专研ViewPaper吧如今说说Gallery画廊,就是不停显示图片的意思 Gallery是用来水平滚动的显示一系列项 ...
- Android 高级UI设计笔记11:Gallery(画廊控件)之Gallery基本使用
1. 这里要向大家介绍Android控件Gallery(画廊控件) Gallery控件主要用于横向显示图像列表,不过按常规做法.Gallery组件只能有限地显示指定的图像.也就是说,如果为Galler ...
- 第29讲 UI组件之 ListView与 BaseAdapter,SimpleAdapter
第29讲 UI组件之 ListView与 BaseAdapter,SimpleAdapter 1.BaseAdapter BaseAdapter是Android应用程序中经常用到的基础数据适配器,它的 ...
- 第16讲- UI组件之TextView
第16讲 UI组件之TextView Android系统所有UI类都是建立在View和ViewGroup这两类的基础上的. 所有View的子类称为widget:所有ViewGroup的子类称为Layo ...
- 第34讲 UI组件之 ProgressDialog和Message
第34讲UI组件之 ProgressDialog和Message 1.进度对话框 ProgressDialog <1>简介 ProgressDialog是AlertDialog类的一个扩展 ...
- 第33讲 UI组件_进度条ProcessBar和消息队列处理器handler
第33讲UI组件_进度条ProcessBar和消息队列处理器handler 1. 进度条ProcessBar 一个可视化的进度指示器,代表正在执行的耗时任务.可以为用户展示一个进度条,表示正在执行的任 ...
- 第30讲 UI组件之 GridView组件
第30讲 UI组件之 GridView组件 1.网格布局组件GridView GridView是一个ViewGroup(布局控件),可使用表格的方式显示组件,可滚动的控件.一般用于显示多张图片,比如实 ...
- 第28讲 UI组件之 ListView和ArrayAdapter
第28讲 UI组件之 ListView和ArrayAdapter 1. Adapter 适配器 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的 ...
随机推荐
- Jmeter接口测试案例实践(一)
1.1. 接口介绍 本次测试的接口采用内网中的通讯录查询接口进行测试,接口参数如下: 1.2. 使用Jmeter进行接口测试 1.2.1. 打开Jmeter 下载好Jmeter后,双击bin目录下的j ...
- 获取布局 ActionBar
LayoutInflater inflater = getLayoutInflater();View imageLayout = inflater.inflate(R.layout.preferenc ...
- TreeGrid( 树形表格)
本节课重点了解 EasyUI 中 TreeGrid(树形表格)组件的使用方法,这个组件依赖于DataGrid(数据表格)组件 一. 加载方式//建立一个 JSON 文件[{"id" ...
- CSS背景特殊属性值
CSS代码示例-背景附着属性(background-attachment)-[背景图固定不动,不跟随滚动条滚动]:<html><head><title>背景附着属性 ...
- JS 函数参数
1.简单的无参函数调用 function Test1(Func) { Func(); } function Test2() { alert("我要被作为函数参数啦!"); } // ...
- Codeforces Round #279 (Div. 2)f
树形最大上升子序列 这里面的上生子序列logn的地方能当模板使 good #include<iostream> #include<string.h> #include< ...
- (转)yum 和 apt-get 用法及区别
原地址:http://www.cnblogs.com/adforce/archive/2013/04/12/3017577.html 一般来说著名的linux系统基本上分两大类: 1 RedHat系 ...
- Ubuntu下安装搜狗拼音输入法
Ubuntu默认输入法是ibus输入法,其实用着也可以了,但是说句实话在某些情况下真的不怎么智能.习惯了搜狗所以,查阅资料测试成功后整理如下, 1.安装搜狗拼音 sudo apt-add-reposi ...
- MySQL 覆盖索引
通常大家都会根据查询的WHERE 条件来穿件合适的索引,不过这只是索引优化的一个方面.设计优秀的索引应该考虑到整个查询,而不单单是WHERE 条件部分.索引确实是一种查找数据的高效方式,但是MySQL ...
- php打印xml格式数据
在你要输出的xml前边加 header("Content-type:text/xml;charset=utf-8"); 这个上边不要有任何输出 打印用echo 别用va ...