android – 在setOnClickListener和setOnTouchListener之间创建不同的东西

android – 在setOnClickListener和setOnTouchListener之间创建不同的东西,第1张

概述我需要一些帮助.在我的 Android应用程序中,我有一个包含一些LinearLayout的ViewFlipper.在每个LinearLayout上我都有一个ImageView.为了在屏幕之间切换,我使用以下代码: LinearLayout layMain = (LinearLayout) findViewById(R.id.layout_main); layMain.setOnT 我需要一些帮助.在我的 Android应用程序中,我有一个包含一些linearLayout的VIEwFlipper.在每个linearLayout上我都有一个ImageVIEw.为了在屏幕之间切换,我使用以下代码:

linearLayout layMain = (linearLayout) findVIEwByID(R.ID.layout_main);        layMain.setontouchListener((OntouchListener) this);

// ————–

public boolean ontouch(VIEw arg0,MotionEvent arg1) {        // Get the action that was done on this touch event        switch (arg1.getAction()) {        case MotionEvent.ACTION_DOWN: {            // store the X value when the user's finger was pressed down            downXValue = arg1.getX();            break;        }        case MotionEvent.ACTION_UP: {            // Get the X value when the user released his/her finger            float currentX = arg1.getX();            // going backwards: pushing stuff to the right            if (downXValue < currentX) {                // Get a reference to the VIEwFlipper                VIEwFlipper vf = (VIEwFlipper) findVIEwByID(R.ID.details);                // Set the animation                vf.setoutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_out));                vf.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_in));                // Flip!                vf.showPrevIoUs();            }            // going forwards: pushing stuff to the left            if (downXValue > currentX) {                // Get a reference to the VIEwFlipper                VIEwFlipper vf = (VIEwFlipper) findVIEwByID(R.ID.details);                // Set the animation                // vf.setInAnimation(AnimationUtils.loadAnimation(this,// R.anim.push_left_in));                vf.setoutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_out));                vf.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_in));                // Flip!                vf.showNext();            }            break;        }        }        // if you return false,these actions will not be recorded        return true;    }

每个屏幕都包含一个ImageVIEw.so,当我切换屏幕时,imagevIEw正在改变.现在我想实现这个:当点击一个图像时,一个url是打开的.这是我的代码:

VIEwFlipper vf = (VIEwFlipper) findVIEwByID(R.ID.details);        for (i = 0; i < jArray.length(); i++) {            linearLayout l = new linearLayout(this);            l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));            l.setBackgroundcolor(0x000000);            l.setorIEntation(linearLayout.VERTICAL);            vf.addVIEw(l);            ImageVIEw img = new ImageVIEw(this);            img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));            Drawable image1 = ImageOperations(getBaseContext(),url[i]);            img.setimageDrawable(image1);            System.out.println("target" + target[i]);            img.setonClickListener(new OnClickListener() {                @OverrIDe                public voID onClick(VIEw v) {                    // Todo auto-generated method stub                    Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri                            .parse("http://Google.com"));                    startActivity(browserIntent);                }            });            l.addVIEw(img);        }

问题是,每当我触摸屏幕时,网址都会打开,现在我无法在屏幕之间切换.如何做到这一点,使onClick()和touch()之间的差异?

请帮我..
提前致谢

解决方法 我认为你使用图像VIEw作为线性布局的背景,似乎Activity处理ImageVIEw的触摸,为imageVIEw实现你的功能settouch监听器,我们可以使用OntouchListener中的以下代码间接处理图像视图的点击,

if (downXValue == currentX) {Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri                        .parse("http://Google.com"));                startActivity(browserIntent);}
总结

以上是内存溢出为你收集整理的android – 在setOnClickListener和setOnTouchListener之间创建不同的东西全部内容,希望文章能够帮你解决android – 在setOnClickListener和setOnTouchListener之间创建不同的东西所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存