2013-09-23 217 views
0

我有一个10个的图像视图内滚动视图OnTouch()的onClick()事件的滚动型

内的视图一旦图像被点击我要执行的操作

但是,当我我试图滚动了滚动Touch_down和Touch_UP的Imags一起被视为点击

帮我出 我知道解决的办法很容易 但我觉得我缺少一些逻辑

我推杆荷兰国际集团我的代码这里

public class CustomScrollView extends ScrollView { 

    public CustomScrollView(Context context) { 
     super(context); 
    } 

    public CustomScrollView(Context context, AttributeSet attrs) { 
      super(context, attrs); 
     } 

    public CustomScrollView(Context context, AttributeSet attrs, int defStyle) { 
      super(context, attrs, defStyle); 
     } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev) { 
     return false; 

    } 

    @Override 
    public boolean onTouchEvent(MotionEvent p_event) { 
     if (p_event.getAction() == MotionEvent.ACTION_MOVE && getParent() != null) { 
      getParent().requestDisallowInterceptTouchEvent(true); 
     } 
     return super.onTouchEvent(p_event); 
    } 
} 

在这种滚动型我增加了一个ImageView的

+0

Plz的家伙建议一个解决方案,而不是使用ListView – user990967

+0

在这里发布你的代码。 –

+0

无代码无人可以帮到你 –

回答

1

嗯,我要去尝试回答.. 我认为(在我看来),你应该的onclick只使用ImageView的,所以当你在滚动型滚动,这ImageView的不会获得点击.. 这里的layout.xml我的代码

样本

<ImageView 
      android:id="@+id/ur_img_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:clickable="true" 
      android:contentDescription="@string/description" 
      android:onClick="onClickEvent" 
      android:src="@drawable/yourDrawable" 
      /> 

然后在你的activity.java进口android.view.View创建活动,创建类似于您在.xml文件使用一个方法,(在例子中的android:的onClick =“onClickEvent”)

public void onClickEvent(View v){ 
     //do your event here 
} 

就是这样。

+0

我试过这个问题仍存在问题存在记住我正在使用customScroll视图,其代码存在于问题中 – user990967