我找不到让这项工作的方法.
我的应用程序有2个FrameLayouts和许多子视图(为简单起见,假设ImageViews),一个堆叠在另一个上.
我的问题是,我需要TOP上的FrameLayout和所有它的孩子让触摸通过它们,到达底层的FrameLayout(及其子节点).像指针事件:HTML中没有应用于TOP framelayout的所有图像视图.
我已经在FrameLayout及其子节点上尝试了setClickable(false)和setEnabled(false),但是如果我单击一个禁用的子节点(例如ImageView),触摸将无法到达底层的ImageView(即底层的子节点)的FrameLayout)
以下代码是我最好的尝试禁用FrameLayout及其子代(mSlideLayout是父FrameLayout,图层是每个imageview子代).我错过了什么?
/** Create the layers structure into the layout */
void create_layers() {
Context context=getActivity();
mSlideLayout.removeAllViews();
for (FunqLayer layer:mLayers) {
if (layer!=null) {
View v=layer.init_internal(context,mSlideLayout); // constructs the child layer,suppose it's an ImageView
if ((v!=null) && (mIsMutetouches)) {
v.setEnabled(false);
v.setClickable(false);
// this should obvIoUsly let touches pass through but it doesnt :(
}
}
}
if (mIsMutetouches) {
// also do the same in the FrameLayout itself with no luck :(
mSlideLayout.setEnabled(false);
mSlideLayout.setClickable(false);
}
}
解决方法
是的,显然我缺少onInterceptTouchEvent,在framelayout中覆盖它并返回true使上述例程变得多余:
FrameLayout slideLayout=new FrameLayout(getActivity()){
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mIsMutetouches) return true;
return super.onInterceptTouchEvent(ev);
}
};