Android:将片段添加到 WindowManager

xXJ*_*kXx 5 android

让我的问题保持简单:如何使用 WindowManager 添加片段?就像你会怎么做WindowManager.addView()?

cha*_*l03 0

将容器布局添加到主布局(ActivityLayout)中,使该布局始终位于顶部,并在该布局中添加片段。就是这样。

看一下下面的 Xml 布局文件:

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

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
    android:id="@+id/frameBottomContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#bbbbbb" >
</FrameLayout>

<FrameLayout
    android:id="@+id/frameTopContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/frameBottomContainer"
    android:layout_gravity="start"
    android:background="#cccccc" >
</FrameLayout>

<FrameLayout
    android:id="@+id/frameExtraViewTopContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start">
</FrameLayout><!-- this is the container that will always be on top-->

</com.bbi.views.FractionRelativeLayout>
Run Code Online (Sandbox Code Playgroud)

现在您可以添加如下片段:

getActivity().getFragmentManager().beginTransaction().add(R.id.frameExtraViewTopContainer,fragment).commitAllowingStateLoss();
Run Code Online (Sandbox Code Playgroud)