首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

Gallery 画廊成效

2012-07-04 
Gallery 画廊效果http://www.cnblogs.com/nokiaguy/archive/2010/08/23/1806870.htmlhttp://smallnopoint.

Gallery 画廊效果
http://www.cnblogs.com/nokiaguy/archive/2010/08/23/1806870.html
http://smallnopoint.iteye.com/blog/725518
1.首先创建实现OnItemSelectedListener,ViewFactory类。
2.创建ImageAdapter类。
3.Activity类。
MyOnItemSelectedListener:当Gallery被选择的时候,把被选择的图片放到ImageSwitch里面去。
MyImageAdapter:实现Gallery显示的图片。
ViewFactory:ImageSwitch的显示工厂。

main.xml



MyOnItemSelectedListener.java
-----------------------
package com.gallery;import android.app.Activity;import android.os.Bundle;import android.view.animation.AnimationUtils;import android.widget.Gallery;import android.widget.ImageSwitcher;public class MyGalleryActivity extends Activity{private Gallery gallery1;private ImageSwitcher imageswitcher1;private int[] images = new int[] { R.drawable.android0001, R.drawable.android0002, R.drawable.android0003, R.drawable.android0004, R.drawable.android0005, R.drawable.android0006, R.drawable.android0007, R.drawable.android0008 };    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                imageswitcher1 = (ImageSwitcher)findViewById(R.id.imageswitcher1);        imageswitcher1.setFactory(new MyViewFactory(MyGalleryActivity.this));        imageswitcher1.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));          imageswitcher1.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));                 gallery1 = (Gallery)findViewById(R.id.gallery1);        gallery1.setAdapter(new MyImageAdapter(this,images));        gallery1.setOnItemSelectedListener(new MyOnItemSelectedListener(imageswitcher1,images));    }}


热点排行