scrollView上的OnClickListener [英] OnClickListener on scrollView
问题描述
我有一个包含很多元素的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屋!