本文实例为大家分享了Android控件ImageSwitcher实现引导界面的代码,供大家参考,具体内容如下
效果图:
布局代码:
<&#63;xml version="1.0" encoding="UTF-8"&#63;>
页面代码:
public class ImageSwitcherActivity extends Activity implements ViewSwitcher.ViewFactory, View.OnTouchListener { private int[] imgIds;//图片id数组 private int currentPosition;//当前选中的图片id序号 private ImageSwitcher mImageSwitcher;//ImagaSwitcher 的引用 private float downX;//按下点的X坐标 private ImageView[] tips;//点点数组 private LinearLayout linearLayout;//装载点点的容器 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_switcher); imgIds = new int[]{R.drawable.bg, R.drawable.c2, R.drawable.c3, R.drawable.c4, R.drawable.c5, R.drawable.c6, R.drawable.c7, R.drawable.c8, R.drawable.c9}; mImageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);//实例化ImageSwitcher mImageSwitcher.setFactory(this); //设置Factory mImageSwitcher.setOnTouchListener(this);//设置OnTouchListener,我们通过Touch事件来切换图片 linearLayout = (LinearLayout) findViewById(R.id.ll_view);//指示器布局 tips = new ImageView[imgIds.length]; for (int i = 0; idownX) { if (currentPosition > 0) { //设置动画 mImageSwitcher.setInAnimation(AnimationUtils.loadAnimation(getApplication(), R.anim.left_in)); mImageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(getApplication(), R.anim.right_out)); currentPosition--; mImageSwitcher.setImageResource(imgIds[currentPosition % imgIds.length]); setImageBackground(currentPosition); } else { Toast.makeText(getApplication(), "已经是第一张", Toast.LENGTH_SHORT).show(); } } if (lastX
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。