DrawerLayout ListView未使用GLSurfaceView作为内容绘制

Tim*_*ler 8 java android listview opengl-es

我的Android应用程序是全屏OpenGL ES 2.0应用程序,因此主要内容是GLSurfaceView的自定义扩展.活动布局如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

然后我使用FrameLayout的addView方法添加我的GLSurfaceView.如果我不这样做,抽屉按预期工作.

当我将其滑入时,ListView似乎被正确拉出,因为我无法再与GLSurfaceView交互,直到我向左滑动它.但它根本没有显示,就像GLSurfaceView总是在它上面渲染一样.

如何使用GLSurfaceView作为其内容使用DrawerLayout?

小智 21

我刚遇到同样的问题,而且我发现了一个非常愚蠢的解决方法.这个问题似乎只会影响DrawerLayouts,而不会影响常规视图.因此,只需在GLSurfaceView上放置一个空视图,即可将其从抽屉屏蔽开.

这是我的精简版布局文件,作为您的示例:

<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>
Run Code Online (Sandbox Code Playgroud)

  • 你先生已经赢得了你的声誉,工作得非常好!动态添加"GL视图"的人的快速说明:在使用索引添加到"ViewGroup"时,只需将其放在后台即可.像这样:`myRelativeLayout.addView(myGlView,0);` (2认同)