在onPause-onResume之后,Android活动视图会将其显示顺序更改为相反

时间:2013-12-03 07:57:53

标签: android android-layout android-lifecycle

我的问题与EditText in listview in opposite order onresume

部分相似

我有3个视图的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <view
        android:id="@+id/above"
        android:layout_width="1px"
        android:layout_height="1px"
        class="com.hooliganslab.stormx.VSurfaceView"
    />

    <view
        android:id="@+id/gl_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.hooliganslab.stormx.GLNativeSurfaceView"
    />

    <view
        android:id="@+id/below"
        android:layout_width="1px"
        android:layout_height="1px"
        class="com.hooliganslab.stormx.VSurfaceView"
    />

</RelativeLayout>

当应用程序启动时(onCreate-onResume)标识为“下方”的视图位于标识为gl_view的视图的下方,标识为“上方”的视图位于标识为gl_view的视图的上方。

当暂停(onPause-onResume)视图后应用程序重新出现时,将其显示顺序更改为相反:标识为“上方”的视图位于标识为gl_view的视图下方,标识为“下方”的视图位于标识为gl_view的视图上方。尽管进一步转换,这个订单仍然保持稳定。

此行为不依赖于使用的布局类型(RelativeLayout或FrameLayout),也不依赖于将视图包装到LinearLayouts中。

如果我为gl_view调用setZOrderMediaOverlay(true),它总是位于“上方”和“下方”视图之上。

如何创建正确且永久的观看顺序?

对不起,我可能含糊不清地提出问题。

android:layout_below修复了平面中视图的相对位置。但是我对z顺序意义上的视图排序很感兴趣。

2 个答案:

答案 0 :(得分:0)

您没有在layout中指定任何职位。使用layout_belowlayout_above指定确切位置

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<view
    android:id="@+id/above"
    android:layout_width="1px"
    android:layout_height="1px"
    class="com.hooliganslab.stormx.VSurfaceView"
/>

<view
    android:id="@+id/gl_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/above" // like this
    class="com.hooliganslab.stormx.GLNativeSurfaceView"
/>

<view
    android:id="@+id/below"
    android:layout_width="1px"
    android:layout_height="1px"
    class="com.hooliganslab.stormx.VSurfaceView"
/>

</RelativeLayout>

答案 1 :(得分:0)

为视图提供ID不会将它们相对于彼此放置。您需要将布局更改为:

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <view
        android:id="@+id/above"
        android:layout_width="1dp"
        android:layout_height="1dp"
        class="com.hooliganslab.stormx.VSurfaceView" />

    <view
        android:id="@+id/gl_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/above"
        class="com.hooliganslab.stormx.GLNativeSurfaceView" />

    <view
        android:layout_below="@id/gl_view"
        android:id="@+id/below"
        android:layout_width="1dp"
        android:layout_height="1dp"
        class="com.hooliganslab.stormx.VSurfaceView" />

</RelativeLayout>