【问题标题】:Android fragment z-index overlayAndroid片段z-index覆盖
【发布时间】:2013-05-18 09:45:48
【问题描述】:

我有两个片段,一个我想要在另一个之上,占据整个屏幕。我该怎么做?

代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:opencv="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_relativelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/MainCameraFragment"
        android:name="com.james.skullyhud.main_camera.MainCameraFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </fragment>

    <fragment
        android:id="@+id/map"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        class="com.google.android.gms.maps.MapFragment" >
    </fragment>

</RelativeLayout>

干杯

【问题讨论】:

  • bringChildToFront 是您可能需要的。看看http://developer.android.com/reference/android/view/ViewGroup.html#bringChildToFront(android.view.View) 。如果有帮助,请告诉我,届时我将作为答案。

标签: java android xml fragment


【解决方案1】:
<RelativeLayout
    android:id="@+id/main_relativelayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/map"
        class="com.google.android.gms.maps.MapFragment"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true">
    </fragment>

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

        <fragment
            android:id="@+id/MainCameraFragment"
            android:name="com.james.skullyhud.main_camera.MainCameraFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </fragment>
    </RelativeLayout>
</RelativeLayout>

【讨论】:

  • 无法编译,缺少 。不知道你打算在哪里。
  • 啊,看到了你的编辑,这就是我自己尝试过的——它有效!这很棒。对于奖励积分,知道如何使 MapFragment 看起来更透明吗?
  • @YoungMoney 你想让哪个片段透明?
  • MapFragment,如果可能的话。
  • @YoungMoney-我认为我们不能让 MapFragment 背景透明..:)
【解决方案2】:

这对我有帮助:

YourFragment.getView().bringToFront();

【讨论】:

  • YourFragment.getView() 经常会返回null
猜你喜欢
  • 2021-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多