scrollView上的OnClickListener [英] OnClickListener on scrollView

查看:73
本文介绍了scrollView上的OnClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含很多元素的scrollView

I have a scrollView with lot of elements

ScrollView scroller = (ScrollView)findViewById(R.id.scrollView);

我需要在滚动视图上附加onClickListener,

I need to attach an onClickListener to the scrollview so I do

scroller.setOnClickListener(new OnClickListener() { 
            @Override
            public void onClick(View v) { 
                // This is all you need to do to 3D flip
                AnimationFactory.flipTransition(viewAnimator, FlipDirection.LEFT_RIGHT); 
            }

        });

但是当我触摸时这不会被触发.有任何想法吗?

But this is not getting triggered when I touch. Any Ideas?

推荐答案

这是因为ScrollView的子级正在获取用户而不是ScrollView的触摸事件.您必须为ScrollView的每个子项都设置clickable = false属性,以使onClickListener可以在ScrollView上工作.

It is because the child of the ScrollView is getting the touch event of the user and not the ScrollView. You must set the clickable=false attribute to each and every child of the ScrollView for the onClickListener to work on ScrollView.

否则,替代方法可能是在每个ScrollView的子级上设置onClickListener并进行处理.

Or else the alternate could be to set the onClickListener on each of the ScrollView's children and handle it.

这篇关于scrollView上的OnClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆