全屏幕ImageSwitcher在Android中没有图库

全屏幕ImageSwitcher在Android中没有图库,第1张

概述我正在尝试在 android中构建一个应用程序,在我的一个活动中,我想要显示全屏图像,并通过在图片上滑动手指使它们左右滑动. 我已经尝试过基本的图库视图和图像切换器但是我无法处理触摸事件以获得滑动效果,就像在自定义安卓库中但没有缩略图一样. 这是我的简单图像切换器xml和活动类.如果有人给我一个方法或编辑我的代码,我将非常感激. 提前致谢… layout xml: <?xml version="1 我正在尝试在 android中构建一个应用程序,在我的一个活动中,我想要显示全屏图像,并通过在图片上滑动手指使它们左右滑动.

我已经尝试过基本的图库视图和图像切换器但是我无法处理触摸事件以获得滑动效果,就像在自定义安卓库中但没有缩略图一样.

这是我的简单图像切换器xml和活动类.如果有人给我一个方法或编辑我的代码,我将非常感激.
提前致谢…

layout xml:

<?xml version="1.0" enCoding="utf-8"?>    <ImageSwitcher     xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:ID="@+ID/imageSwitcher"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:layout_alignParentBottom="true"    androID:layout_alignParentleft="true"    androID:layout_alignParenttop="true"    androID:onClick="imageClick"    androID:src="@drawable/ic_launcher"    androID:keepScreenOn="true">    </ImageSwitcher>

代码:

public class galleryActivity extends Activity implements VIEwFactory {    private ImageSwitcher imageSwitcher ;    @OverrIDe      public voID onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentVIEw(R.layout.activitIEs);           imageSwitcher = (ImageSwitcher) findVIEwByID(R.ID.imageSwitcher);         imageSwitcher.setFactory(this);         imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,androID.R.anim.fade_in));         imageSwitcher.setoutAnimation(AnimationUtils.loadAnimation(this,androID.R.anim.fade_out));         imageSwitcher.setimageResource(R.drawable.menu);         imageSwitcher.setontouchListener(new OntouchListener() {            public boolean ontouch(VIEw v,MotionEvent event) {                findVIEwByID(R.drawable.menu);                imageSwitcher.addVIEw((ImageSwitcher) findVIEwByID(R.drawable.etkinlik));                imageSwitcher.showNext();                return false;            }        });    }          public VIEw makeVIEw() {          ImageVIEw iVIEw = new ImageVIEw(this);        iVIEw.setScaleType(ImageVIEw.ScaleType.FIT_CENTER);        iVIEw.setLayoutParams(new                    ImageSwitcher.LayoutParams(                                LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));        iVIEw.setBackgroundcolor(0xFF000000);        return iVIEw;    }}

在编辑了@imran khan的一些解决方案后,这里的代码运行得非常好.

解:

ImageSwitcher imageSwitcher ;Integer[] imageList = {        R.drawable.gallery,R.drawable.menu,R.drawable.promotion,R.drawable.info,R.drawable.activitIEs       };int curIndex=0;int downX,upX;@OverrIDe  public voID onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);       setContentVIEw(R.layout.activitIEs);       imageSwitcher = (ImageSwitcher) findVIEwByID(R.ID.imageSwitcher);     imageSwitcher.setFactory(this);     imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,androID.R.anim.fade_in));     imageSwitcher.setoutAnimation(AnimationUtils.loadAnimation(this,androID.R.anim.fade_out));     imageSwitcher.setimageResource(imageList[curIndex]);     imageSwitcher.setontouchListener(new OntouchListener() {     @OverrIDe     public boolean ontouch(VIEw v,MotionEvent event) {         if (event.getAction() == MotionEvent.ACTION_DOWN) {             downX = (int) event.getX();              Log.i("event.getX()"," downX " + downX);             return true;         }          else if (event.getAction() == MotionEvent.ACTION_UP) {             upX = (int) event.getX();              Log.i("event.getX()"," upX " + downX);             if (upX - downX > 100) {                 //curIndex  current image index in array vIEwed by user                 curIndex--;                 if (curIndex < 0) {                     curIndex = imageList.length-1;                 }                 imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(galleryActivity.this,R.anim.slIDe_in_left));                 imageSwitcher.setoutAnimation(AnimationUtils.loadAnimation(galleryActivity.this,R.anim.slIDe_out_right));                 imageSwitcher.setimageResource(imageList[curIndex]);                 //galleryActivity.this.setTitle(curIndex);             }              else if (downX - upX > -100) {                 curIndex++;                 if (curIndex > 4) {                     curIndex = 0;                 }                 imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(galleryActivity.this,R.anim.slIDe_in_right));                 imageSwitcher.setoutAnimation(AnimationUtils.loadAnimation(galleryActivity.this,R.anim.slIDe_out_left));                 imageSwitcher.setimageResource(imageList[curIndex]);                 //galleryActivity.this.setTitle(curIndex);             }                 return true;             }             return false;         }     });}@OverrIDepublic VIEw makeVIEw() {    ImageVIEw i = new ImageVIEw(this);      i.setScaleType(ImageVIEw.ScaleType.FIT_CENTER);    return i;}
解决方法 试试这种方式:

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);imageSwitcher1.setontouchListener(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));                mageSwitcher1.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;         }     };

如果你有图像阵列,那么试试这个:

imgSwitcher.setontouchListener(new OntouchListener() {            @OverrIDe            public boolean ontouch(VIEw v,MotionEvent event) {                // Todo auto-generated method stub                if (event.getAction() == MotionEvent.ACTION_DOWN) {                    downX = (int) event.getX();                     Log.i("event.getX()"," downX " + downX);                    return true;                } else if (event.getAction() == MotionEvent.ACTION_UP) {                    upX = (int) event.getX();                     Log.i("event.getX()"," upX " + downX);                    if (upX - downX > 100) {                        imgSwitcher.setInAnimation(AnimationUtils                        .loadAnimation(firstActivity.this,androID.R.anim.slIDe_in_left));                        imgSwitcher.setoutAnimation(AnimationUtils                         .loadAnimation(firstActivity.this,androID.R.anim.slIDe_out_right));                         //curIndex  current image index in array vIEwed by user                        curIndex--;                        if (curIndex < 0) {                            curIndex = 5;                        }                        //IMAGE_List :-image List array                        imgSwitcher.setimageResource(IMAGE_List[curIndex]);                        firstActivity.this.switchTitle(curIndex);                    } else if (downX - upX > 100) {                         imgSwitcher.setInAnimation(AnimationUtils                        .loadAnimation(firstActivity.this,R.anim.slIDe_out_left));                        imgSwitcher.setoutAnimation(AnimationUtils                        .loadAnimation(firstActivity.this,R.anim.slIDe_in_right));                        curIndex++;                        if (curIndex > 5) {                            curIndex = 0;                        }                        imgSwitcher.setimageResource(IMAGE_List[curIndex]);                        firstActivity.this.switchTitle(curIndex);                    }                    return true;                }                return false;            }        });
总结

以上是内存溢出为你收集整理的全屏幕ImageSwitcher在Android中没有图库全部内容,希望文章能够帮你解决全屏幕ImageSwitcher在Android中没有图库所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1127085.html

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

发表评论

登录后才能评论

评论列表(0条)

保存