【问题标题】:DrawerLayout ListView not drawn with GLSurfaceView as contentDrawerLayout ListView 未使用 GLSurfaceView 作为内容绘制
【发布时间】:2014-07-04 15:42:49
【问题描述】:

我的 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>

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

当我滑入 ListView 时,它似乎被正确拉出,因为我无法再与 GLSurfaceView 交互,直到我将它滑回左侧。但它根本不显示,就像 GLSurfaceView 总是呈现在它上面。

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

【问题讨论】:

    标签: java android listview opengl-es


    【解决方案1】:

    我刚刚遇到了同样的问题,我发现了一个非常愚蠢的解决方法。这个问题似乎只影响 DrawerLayouts,而不影响常规 Views。因此,只需在 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>
    

    【讨论】:

    • 您先生赢得了您的声誉,工作非常出色!给动态添加GL View 的人的快速说明:在使用索引添加到ViewGroup 时,只需将其置于后台即可。像这样:myRelativeLayout.addView(myGlView, 0);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-17
    • 2016-09-28
    • 2012-10-24
    • 1970-01-01
    • 2012-12-24
    • 2013-10-30
    相关资源
    最近更新 更多