Reputation: 231
I have layout like following.
<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 is my customView extended from GestureOverlayView. It looks like following..
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);
}
}
If user clicks on imageview(id = icon), i dont want to pass touch event to linearlayout. if user clicks on framelayout(id = content_frame), i want to pass touch event to linearlayout to support onclick of button. Can anybody suggest me how to do this?
Ontouch of image view and 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;
}
});
Upvotes: 2
Views: 4834
Reputation: 73753
if you want to pass down the touch then return false (not handled) in the onTouch
if you dont want to pass it down the return true (handled). all you have to do is then find out what view was touched
Upvotes: 1