(android控件)ImageSwitcher介绍和使用说明
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;
}
};
点击打开链接更多相关文章
- 推荐4个Android引导页控件
- Android(安卓)常用基本控件 ImageButton
- [Android] Adapter:SimpleAdapter SimpleCursorAdapter ArrayAda
- android 下载保存图片
- Android中的动画--笔记
- imageview 自适应各种屏幕尺寸
- Android中加载PNG图片时出现错误----No resource found
- Android(安卓)获取系统和应用程序
- Android加载png图片时出错