我有這樣一個佈局:onTouch()不會調用父佈局
LinearLayout
RelativeLayout(id = test)
FrameLayout (From a LIB. id = lib)
我嘗試添加onTouchListener()
到test
,但它不工作。
我想:
@OnTouch(R.id.test)
public boolean test(View v,MotionEvent e) { NOT WORK }
,我嘗試一個簡單的監聽器:
test.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
NOT WORK
return false;
}
});
我試圖偵聽器添加到FrameLayout
但沒有工作過。
我不想修改庫。 任何人有想法使用OnTouch
事件?
<RelativeLayout
android:id="@+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
android:layout_weight="1">
<com.flurgle.camerakit.CameraView
android:id="@+id/camera"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
app:ckCropOutput="false"
app:ckFacing="back"
app:ckFlash="off"
app:ckFocus="continuous"
app:ckJpegQuality="100"
app:ckMethod="standard"/>
<TextView
在CameraView:
focusMarkerLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (motionEvent.getAction() == MotionEvent.ACTION_UP && mFocus == CameraKit.Constants.FOCUS_TAP_WITH_MARKER) {
focusMarkerLayout.focus(motionEvent.getX(), motionEvent.getY());
}
mPreviewImpl.getView().dispatchTouchEvent(motionEvent);
return true;
}
});
感謝。
解決方案:
LinearLayout
RelativeLayout(id = test)
CustomRelativeLayout()
FrameLayout (From a LIB. id = lib)
創建CustomRelativeLayout
public class CustomRelativeLayout extends RelativeLayout{
public CustomRelativeLayout(Context context) {
super(context);
}
public CustomRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return false;
}
}
問題:
Touch
-> Activity:dispatchTouchEvent
-> LinearLayout:dispatchTouchEvent
-> CustomRelativeLayout:dispatchTouchEvent
-> CameraView:dispatchTouchEvent (return true) STOPPED everything
解決方案:
Touch
-> Activity:dispatchTouchEvent
-> LinearLayout:dispatchTouchEvent
-> CustomRelativeLayout:dispatchTouchEvent
-> CustomRelativeLayout:onTouch
-> LinearLayout:onTouch
-> Activity:onTouch (IT WORK :))
我做了我的自定義佈局@覆蓋 公共布爾dispatchTouchEvent(MotionEvent EV){ 返回FALSE; } 但它不能正常工作 – ketom
這隻會幫助你調試'MotionEvent's,看看發生了什麼,這是不應該幫助你在任何方面。另外,返回'false'將不允許將這個'MotionEvent'派發給子代,而是返回'true'來讓'FrameLayout'處理點擊。 – azizbekian
當我觸摸屏幕時,CustomLayouts調度運行。 – ketom