我想结合使用DrawerLayout和SurfaceView (MetaioSDK增强现实视图)。除了TouchListener的SurfaceView之外,一切都很好。看起来,FrameLayout在DrawerlLayout中阻塞了SurfaceView的Touch事件。是否可以将事件直接委托给SurfaceView?我会感谢一些专业人士的帮助。
下面是我的xml布局
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</FrameLayout>
<LinearLayout
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:orientation="vertical" >
<TextView
android:id="@+id/tV_Attributes"
android:layout_width="240dp"
android:layout_height="match_parent"
android:text="Hier sollen Attribute angezeigt werden." />
</LinearLayout>
发布于 2015-05-22 09:26:50
如果FrameLayout是在SurfaceView上降落的,则需要扩展它以忽略触摸事件。
在FrameLayout中:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (isHitToView(ev, view)) {
return false;
} else {
return super.onInterceptTouchEvent(ev);
}
}
public static boolean isHitToView(MotionEvent event, View view) {
if (view == null || event == null || view.getVisibility() != View.VISIBLE)
return false;
Rect r = new Rect();
//r.left и r.top - всегда нули
view.getLocalVisibleRect(r);
int[] coordinates = new int[2];
view.getLocationOnScreen(coordinates);
r.left += coordinates[0];
r.right += coordinates[0];
r.top += coordinates[1];
r.bottom += coordinates[1];
float x = event.getRawX();
float y = event.getRawY();
if (r.right >= x && r.top <= y && r.left <= x && r.bottom >= y)
return true;
return false;
}https://stackoverflow.com/questions/30392721
复制相似问题