很赞的引导界面效果Android控件ImageSwitcher实现

很赞的引导界面效果Android控件ImageSwitcher实现,第1张

概述本文实例为大家分享了Android控件ImageSwitcher实现引导界面的代码,供大家参考,具体内容如下

本文实例为大家分享了AndroID控件ImageSwitcher实现引导界面的代码,供大家参考,具体内容如下

效果图:

布局代码:

<?xml version="1.0" enCoding="UTF-8"?><FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"       androID:layout_wIDth="fill_parent"       androID:layout_height="fill_parent">  <ImageSwitcher    androID:ID="@+ID/imageSwitcher"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent">  </ImageSwitcher>  <relativeLayout    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical">    <linearLayout      androID:ID="@+ID/ll_vIEw"      androID:layout_wIDth="fill_parent"      androID:layout_height="wrap_content"      androID:layout_alignParentBottom="true"      androID:layout_marginBottom="30dp"      androID:gravity="center_horizontal"      androID:orIEntation="horizontal">    </linearLayout>  </relativeLayout></FrameLayout>

页面代码:

public class ImageSwitcherActivity extends Activity implements VIEwSwitcher.VIEwFactory,VIEw.OntouchListener {  private int[] imgIDs;//图片ID数组  private int currentposition;//当前选中的图片ID序号  private ImageSwitcher mImageSwitcher;//ImagaSwitcher 的引用  private @R_301_5987@ 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; i < imgIDs.length; i++) {      ImageVIEw mImageVIEw = new ImageVIEw(this);      tips[i] = mImageVIEw;      linearLayout.LayoutParams layoutParams = new linearLayout.LayoutParams(new VIEwGroup.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));      layoutParams.rightmargin = 3;      layoutParams.leftmargin = 3;      mImageVIEw.setBackgroundResource(R.drawable.page_indicator_unfocused);      linearLayout.addVIEw(mImageVIEw,layoutParams);    }    //上一个界面传过来的位置    currentposition = getIntent().getIntExtra("position",0);    mImageSwitcher.setimageResource(imgIDs[currentposition]);    setimagebackground(currentposition);  }  //设置选中的tip的背景  private voID setimagebackground(int selectItems) {    for (int i = 0; i < tips.length; i++) {      if (i == selectItems) {        tips[i].setBackgroundResource(R.drawable.page_indicator_focused);      } else {        tips[i].setBackgroundResource(R.drawable.page_indicator_unfocused);      }    }  }  @OverrIDe  public VIEw makeVIEw() {    final ImageVIEw i = new ImageVIEw(this);    i.setBackgroundcolor(0xff000000);    i.setScaleType(ImageVIEw.ScaleType.CENTER_CROP);    i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));    return i;  }  @OverrIDe  public boolean ontouch(VIEw v,MotionEvent event) {    switch (event.getAction()) {      case MotionEvent.ACTION_DOWN: {        downX = event.getX();//手指按下的X坐标        break;      }      case MotionEvent.ACTION_UP: {        @R_301_5987@ lastX = event.getX();        //抬起的时候的X坐标大于按下的时候就显示上一张图片        if (lastX > downX) {          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 < downX) {          if (currentposition < imgIDs.length - 1) {            mImageSwitcher.setInAnimation(AnimationUtils.loadAnimation(getApplication(),R.anim.right_in));            mImageSwitcher.setoutAnimation(AnimationUtils.loadAnimation(getApplication(),R.anim.lift_out));            currentposition++;            mImageSwitcher.setimageResource(imgIDs[currentposition]);            setimagebackground(currentposition);          } else {            Toast.makeText(getApplication(),"到了最后一张",Toast.LENGTH_SHORT).show();          }        }      }      break;    }    return true;  }}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

总结

以上是内存溢出为你收集整理的很赞的引导界面效果Android控件ImageSwitcher实现全部内容,希望文章能够帮你解决很赞的引导界面效果Android控件ImageSwitcher实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1149222.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存