Android 在其他片段上方显示片段

Android 在其他片段上方显示片段,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,基本上,我想做的是: 1.-我有两个片段“在”活动之外。 2.-现在可能有两种可能性,片段1或片段必须用幻灯片动画显示。 3.-当两个片段都在屏幕上时,片段1始终位于片段2上方。 4.-任何片段都可以隐藏,将显示片段正确放置在屏幕底部。 我对布局设计有点迷茫。我试过了 <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <F

基本上,我想做的是:

1.-我有两个片段“在”活动之外。 2.-现在可能有两种可能性,片段1或片段必须用幻灯片动画显示。 3.-当两个片段都在屏幕上时,片段1始终位于片段2上方。 4.-任何片段都可以隐藏,将显示片段正确放置在屏幕底部。 我对布局设计有点迷茫。我试过了

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

    <FrameLayout
        android:id="@+id/fragment1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="-20dp"
        android:visibility="gone" />

    <FrameLayout
        android:id="@+id/fragment2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="-20dp"
        android:visibility="gone" />

</RelativeLayout> 

我甚至同时展示了它们。甚至对每个片段使用不同的FragmentTransaction。使用上面的,
android:layout\u
不起作用

开发此设计的最简单方法是什么

试试这个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="-100dp"
        android:orientation="vertical">

        <FrameLayout
            android:id="@+id/fragment1"
            android:layout_width="match_parent"
            android:layout_height="50dp"
           android:background="@color/colorAccent"
            />

        <FrameLayout
            android:id="@+id/fragment2"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@color/colorPrimary"
            />

    </LinearLayout>

</RelativeLayout>


设置线性布局的动画。根据您的要求更改framelayout(gone/visible)的可视性

也许对FragmentA使用两个framelayout将有助于这两种场景

  • 当它是您唯一可以使用的可见对象时 android:layout\u alignParentBottom=“true”

  • 当它位于FrameLayout上保存FragmentB时,您可以使用 android:layout_over=“@+id/fragment2”

  • 然后根据您的场景来处理这些场景的“可视性”