AndroidTagView
AndroidTagView copied to clipboard
TagView截获了父布局的点击事件
您好,我在使用过程中,发现TagContainerLayout在ScrollView中工作的不是很好, 假设 TagContainerLayout 外层包裹了一层Layout,Layout可以点击。理想情况是TagContainerLayout不应该处理任何Touch事件,它也工作的很好,但现在出现了两种情况: 1、点到了TagView,外层的Layout会回调onClick ,但此时滑动手指,滑动事件失效。 2、于是将TagView的dispatchTouchEvent修改,直接返回true。点击TagView,Layout收不到onClick回调,但滑动事件有效。 TagView影响了其它控件的行为,无论dispatchTouchEvent怎么返回,要么不能点击,要么不能滑动,我暂时找不到解决的办法。
逗了, 一直找TagView的Touch事件的问题,其实在TagContainerLayout中重写dispatchTouchEvent返回false截获事件,TagView连事件都收不到就没那么多事了。
请问怎样重写 dispatchTouchEvent 呢?
写个类继承TagContainerLayout ,重写 dispatchTouchEvent 直接返回false;
public class GMTagContainerLayout extends TagContainerLayout {
public GMTagContainerLayout(Context context) {
super(context);
}
public GMTagContainerLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GMTagContainerLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return false;
}
}
重写TagContainerLayout之后,布局文件中怎么写呢?
<co.lujun.androidtagview.GMTagContainerLayout
android:id="@+id/home_big_image_item_tag_view"
android:layout_below="@+id/tv_item_title"
android:layout_width="wrap_content"
android:layout_height="25dp"/>
报错:android.view.InflateException: Binary XML file line #33: Error inflating class co.lujun.androidtagview.GMTagContainerLayout
你确定这个类包名啥的写的正确? 项目找不到你的类
那布局文件中应该怎么写?