2014-05-16 16 views
7

Ứng dụng Android của tôi là ứng dụng OpenGL ES 2.0 toàn màn hình, vì vậy nội dung chính là phần mở rộng tùy chỉnh của GLSurfaceView. bố trí Các hoạt động trông như thế này:DrawerLayout ListView không được vẽ bằng GLSurfaceView dưới dạng nội dung

<android.support.v4.widget.DrawerLayout 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/drawer_layout"> 
    <FrameLayout android:id="@+id/content_frame" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
    <ListView android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:background="#111" /> 
</android.support.v4.widget.DrawerLayout> 

Sau đó tôi thêm GLSurfaceView của tôi bằng cách sử dụng phương pháp addView của FrameLayout. Nếu tôi không làm điều này, ngăn kéo hoạt động như mong đợi.

ListView dường như được lấy ra chính xác khi tôi trượt nó vào, vì tôi không thể tương tác với GLSurfaceView nữa cho đến khi tôi vuốt nó trở lại bên trái. Nhưng nó không được hiển thị ở tất cả, như GLSurfaceView là allways rendered ontop của nó.

Làm cách nào để có một DrawerLayout hoạt động với GLSurfaceView làm nội dung của nó?

Trả lời

16

Tôi vừa đối mặt với cùng một vấn đề và tôi đã tìm thấy một giải pháp khá ngớ ngẩn cho nó. Sự cố này dường như chỉ ảnh hưởng đến DrawerLayouts và không ảnh hưởng đến Chế độ xem thông thường. Vì vậy, chỉ cần đặt Chế độ xem trống trên GLSurfaceView của bạn, để che dấu nó khỏi Ngăn kéo.

Dưới đây là tước xuống tập tin bố trí của tôi như là một mẫu dành cho bạn:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <GLSurfaceView 
      android:id="@+id/glSurfaceView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </RelativeLayout> 


    <FrameLayout 
     android:id="@+id/frameLayoutDrawer" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="end" 
     android:background="@android:color/white" /> 
</android.support.v4.widget.DrawerLayout> 
+1

Bạn thưa ông đã giành được danh tiếng của mình, làm việc tuyệt vời! Một lưu ý nhanh cho những người thêm 'GL View' động của họ: Đơn giản chỉ cần đặt nó trong nền khi thêm vào' ViewGroup' với một chỉ mục. Như thế này: 'myRelativeLayout.addView (myGlView, 0);' – avalancha

Các vấn đề liên quan