2012-06-12 45 views
4

可以将碎片“堆叠”在彼此之上吗?Android中的Z-Layering碎片

只是试图做到这一点,而没有真正考虑它,一切都变得有点疯狂。 我可以(也可能应该)创建一个ViewGroup,如果这是不可能的,但我只是想知道。

回答

10

是的,这是可能的。例如。通过包装他们FrameLayout像这里面:

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

    <fragment android:name="com.package.FragmentOne" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      /> 

    <fragment android:name="com.package.FragmentTwo" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      /> 

</FrameLayout> 

的Z-index取决于布局中的儿童的数量级上。在这个例子中,FragmentTwo高于FragmentOne,因为它是第二个孩子。

+3

这也可以在'RelativeLayout'中完成 – edthethird

+0

您是否真的尝试过这种方法并使其工作?我正在制作一个导航片段,并确保它在我的RelativeLayout中处于顶部,但它完全将布局搞乱了。 –

+0

@FrankSposaro是的,在回答之前在一个小样本项目中进行了测试。 [这里](https://dl.dropbox.com/u/17220543/Test.zip)是该项目,看看它是否可以帮助你。 – 2012-06-12 15:23:12