ImageSwitcher 和 Gallery 的使用
来源:互联网 发布:淘宝一择数码这个店铺 编辑:程序博客网 时间:2024/04/28 08:04
ImageSwitcher 是一个用于图片浏览的控件,使用这个空间有一个好处就是可以设置图片的进入和退出的动画效果总体来说看着还是很不错的。而gallery即画廊是平时开发中常用到的图片浏览空间,其默认是第一张图在中间显示,若需要其左对齐 则需要对该空间进行重写,网上有很多这样的代码。现在直接上代码,注释都有的。
package com.igallerybate.activity;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.view.ViewGroup.LayoutParams;import android.view.animation.AnimationUtils;import android.widget.AdapterView;import android.widget.AdapterView.OnItemSelectedListener;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.ViewSwitcher.ViewFactory;public class IGallleryBateActivity extends Activity implements ViewFactory {private Gallery gl = null;private ImageSwitcher is = null;private int[] res = new int[]{R.drawable.t1,R.drawable.t2,R.drawable.t3,R.drawable.t4,R.drawable.t5,R.drawable.t6,R.drawable.t7};@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);is = (ImageSwitcher) this.findViewById(R.id.is_image);is.setFactory(this);//需要实现 makeView()方法is.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));//ImageSwitcher退出动画is.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));//ImageSwitcher进入动画。。这两个动画可以自己定义的gl = (Gallery) this.findViewById(R.id.gl);gl.setAdapter(new GalleryAdapter());gl.setOnItemSelectedListener(new OnItemSelectedListener() {@Overridepublic void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {is.setBackgroundResource(res[arg2]);}@Overridepublic void onNothingSelected(AdapterView<?> arg0) {// TODO Auto-generated method stub}});}@Overridepublic View makeView() {//该方法有用来实现ViewFactory 方法。ImageView iv = new ImageView(getApplicationContext());//注意用的是ImageSwitcher.LayoutParams iv.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));return iv;} class GalleryAdapter extends BaseAdapter{@Overridepublic int getCount() {// TODO Auto-generated method stubreturn res.length;}@Overridepublic Object getItem(int arg0) {// TODO Auto-generated method stubreturn res[arg0];}@Overridepublic long getItemId(int arg0) {// TODO Auto-generated method stubreturn arg0;}@Overridepublic View getView(int arg0, View arg1, ViewGroup arg2) {ImageView iv = new ImageView(getApplicationContext());iv.setLayoutParams(new Gallery.LayoutParams(120,120));//设置Imageview控件的的大小iv.setBackgroundResource(res[arg0]);//设置图片显示iv.setAlpha(150);//设置imageview控件半透明的return iv;} }}
布局文件
<?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" android:orientation="vertical" > <ImageSwitcher android:id="@+id/is_image" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <RelativeLayout android:layout_width="fill_parent" android:layout_height="100dip" android:layout_alignParentBottom="true" > <Gallery android:id="@+id/gl" android:layout_width="fill_parent" android:layout_height="fill_parent" android:spacing="5dip" /> </RelativeLayout></RelativeLayout>
实现效果
这里说明一下,为什么程序用的程序使用的是adpater 是定义的一个内部类,使用内部类的好处在于有些数据调用十分方便,如果有需要的话,可以留言,我可以把它分离出来。
源码地址:http://download.csdn.net/detail/luinsist/4790672
- ImageSwitcher 和 Gallery 的使用
- ImageSwitcher和Gallery的使用
- Android中Gallery和ImageSwitcher的使用
- Android中Gallery和ImageSwitcher的使用
- ImageSwitcher和Gallery的运用
- android中画廊视图Gallery和ImageSwitcher组件的使用
- 使用ImageSwitcher和Gallery实现图片的浏览
- 使用ImageSwitcher和Gallery实现图片的浏览
- ImageSwitcher&Gallery组件和GridView组件的使用
- Gallery单独使用,Gallery和ImageSwitcher组件结合使用的例子
- Android ImageSwitcher和Gallery 综合使用
- Android ImageSwitcher和Gallery 综合使用
- Android 中的ImageSwitcher 和Gallery结合使用
- android ImageSwitcher和Gallery组合使用
- Android ImageSwitcher和Gallery 综合使用
- 使用ImageSwitcher和Gallery实现左右滑动
- 使用ImageSwitcher和Gallery实现左右滑动
- 使用Gallery和ImageSwitcher制作图片浏览器
- java并发编程下变量可见行分析
- 蝴蝶效应、青蛙现象、鳄鱼法则、鲇鱼效应、羊群效应、刺猬法则
- 使用putty访问ubuntu
- 贪吃蛇代码有错,大家一起来指错吧
- ImageSwitcher 和 Gallery 的使用
- u 如何安装linux操作系统 及远程维护
- VMWare workstation 和 player区别
- MessageBox的常见用法
- char* 和char[]的区别
- Rubber-Banding with OpenGL
- 仿百度词条查询(利用ajax和json技术)
- C语言union中包含struct 小结
- BASIC IMAGE PROCESSING TUTORIAL