【发布时间】:2014-05-21 07:46:07
【问题描述】:
我有如下布局。
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<Button/><Button/>
</LinearLayout>
<DisabledGestureView android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:layout_width="match_parent"
id="@+android/content_frame"
android:layout_height="match_parent">
<ImageView android:layout_width="200dp"
id="@+android/icon"
android:layout_height="200dp">
</FrameLayout>
</DisabledGestureView>
</FrameLayout>
DisableGestureView 是我从 GestureOverlayView 扩展而来的 customView。它看起来像以下..
public class DisabledGestureView extends GestureOverlayView {
public DisabledGestureView(Context context) {
super(context);
}
private boolean mIsDisable = true;
public void setDisableStatus(boolean status) {
mIsDisable = status;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
MLog.d("", "overlay touch : " + mIsDisable);
if (mIsDisable) {
return false;
}
return super.onTouchEvent(ev);
}
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mIsDisable) {
return false;
}
return super.dispatchTouchEvent(ev);
}
}
如果用户点击 imageview(id = icon),我不想将触摸事件传递给线性布局。如果用户点击框架布局(id = content_frame),我想将触摸事件传递给线性布局以支持按钮的点击。任何人都可以建议我如何做到这一点?
图像视图和frameLayout的Ontouch:
imageview.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
disabledGestureView.setDisableStatus(false);
return false;
}
});
framelayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
disabledGestureView.setDisableStatus(true);
return false;
}
});
【问题讨论】:
-
在 imageView 的 onTouch 中我调用 DisabledGestureView.setDisableStatus(false);在 framelayout(id = content_frame) 的 onTouch 中,我正在调用 DisabledGestureView.setDisableStatus(true);允许/允许触摸事件在 DisabledGestureView 的视图下方。但它没有用。
标签: android view touch gesture touch-event