我的布局如下。
<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),我不想将触摸事件传递给linearlayout。如果用户点击framelayout(id = content_frame),我想将touch事件传递给linearlayout以支持onclick按钮。谁能建议我怎么做?
图像视图的固定和frameLayout:
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;
}
});
答案 0 :(得分:1)
如果你想传递触摸然后在onTouch
中返回false(未处理),如果你不想传递它返回true(已处理)。所有你需要做的就是找出被触摸的视图