1 ImageSwitcher实现的功能 和实际运行的效果图示意

ImageSwitcher类提供了图片切换功能,通过第三方的操作,设置当前ImageSwitcher显示的图片,同时设置图片变换的动画。

2 如何使用ImageSwitcher控件

2.1 配置页面文件

<imageswitcher< p="">

android:id="@+id/imageSwitcher1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_alignLeft="@+id/textView1"

android:layout_above="@id/adLayout"

android:layout_below="@id/topText"

android:layout_centerVertical="true" >

3 初始化ImageSwitcher控件

初始化ViewPager控件的适配器

imageSwitcher1 = (ImageSwitcher) findViewById(R.id.imageSwitcher1);

imageSwitcher1.setFactory(this);

imageSwitcher1.setInAnimation(AnimationUtils.loadAnimation(this,

android.R.anim.fade_in));

imageSwitcher1.setOutAnimation(AnimationUtils.loadAnimation(this,

android.R.anim.fade_out));

imageSwitcher1.setImageResource(R.drawable.girl2);

4 根据界面滑动的方向切换图片

OnTouchListener touchlistener = new OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

if (event.getAction() == MotionEvent.ACTION_DOWN) {

downX = (int) event.getX();

return true;

} else if (event.getAction() == MotionEvent.ACTION_UP) {

upX = (int) event.getX();

if (upX - downX > 100) {

imageSwitcher1.setInAnimation(AnimationUtils.loadAnimation(ShowPhotoActivity.this,

android.R.anim.slide_in_left));

imageSwitcher1.setOutAnimation(AnimationUtils.loadAnimation(ShowPhotoActivity.this,

android.R.anim.slide_out_right));

imageSwitcher1.setImageResource(R.drawable.girl1);

} else if (downX - upX > 100)// {

imageSwitcher1.setInAnimation(AnimationUtils.loadAnimation(ShowPhotoActivity.this,

android.R.anim.slide_in_left));

imageSwitcher1.setOutAnimation(AnimationUtils.loadAnimation(ShowPhotoActivity.this,

android.R.anim.slide_out_right));

imageSwitcher1.setImageResource(R.drawable.girl2);

}

return true;

}

return false;

}

};

点击打开链接

更多相关文章

  1. 推荐4个Android引导页控件
  2. Android(安卓)常用基本控件 ImageButton
  3. [Android] Adapter:SimpleAdapter SimpleCursorAdapter ArrayAda
  4. android 下载保存图片
  5. Android中的动画--笔记
  6. imageview 自适应各种屏幕尺寸
  7. Android中加载PNG图片时出现错误----No resource found
  8. Android(安卓)获取系统和应用程序
  9. Android加载png图片时出错

随机推荐

  1. Android(安卓)Wifi相关广播 -- WIFI_STAT
  2. android中handler的使用
  3. [置顶] android 捕捉异常
  4. Android(安卓)封装http请求的工具类
  5. Android(安卓)打开闪光灯(手电筒)
  6. Android(安卓)多层树完美实现
  7. android 如何屏蔽Home键(长按短按都不起作
  8. Android(安卓)Telephony 分析[PART IV]
  9. android:Handler开启线程定时循环
  10. Android学习--Android带删除按钮的ListVi