Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使片段完全位于framelayout内部_Android_Android Fragments_Android Framelayout - Fatal编程技术网

Android 使片段完全位于framelayout内部

Android 使片段完全位于framelayout内部,android,android-fragments,android-framelayout,Android,Android Fragments,Android Framelayout,在我的应用程序中,我想在所有屏幕的底部保留一个相同的广告横幅,因此我使用一个包含多个片段的活动 在活动的布局文件(Activity_mail.xml)中,我有一个FrameLayout作为片段的容器,在底部有一个AdView来显示来自Admob的横幅广告 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas

在我的应用程序中,我想在所有屏幕的底部保留一个相同的广告横幅,因此我使用一个包含多个片段的活动

在活动的布局文件(Activity_mail.xml)中,我有一个FrameLayout作为片段的容器,在底部有一个AdView来显示来自Admob的横幅广告

 <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        tools:ignore="MergeRootFrame">
        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        <fragment
            android:id="@+id/adFragment"
            android:name="com.jiyuzhai.wangxizhishufazidian.MainActivity$AdFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
</RelativeLayout>
但是当我替换容器中的片段时,片段的底部区域被AdView隐藏,换句话说,片段在Framelayout之外,我希望片段完全在容器中。可能吗

以下是我想要的

这就是我得到的(广告横幅隐藏了片段的底部栏)

有什么想法吗

顺便说一句,我发现没有办法在Android中为所有包含多个活动的屏幕保留相同的横幅,很多人说你需要使用带有多个片段的单个活动,然后你可以动态添加/删除片段,而无需重新加载新的横幅,但是,没有找到这种方法的代码,所以我自己尝试。如果您有更好的解决方案,请帮助我。

试试这个:

 <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        tools:ignore="MergeRootFrame">
        <fragment
            android:id="@+id/adFragment"
            android:name="com.jiyuzhai.wangxizhishufazidian.MainActivity$AdFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/adFragment" />
</RelativeLayout>

我对原始布局文件所做的更改是将adFragment定义移动到框架布局上方,使框架布局高度包裹内容,并在上面添加了
layout\u
属性,以使框架布局显示在广告片段上方

另一种方法是使用垂直线性布局,首先使用布局权重为1的框架布局(而广告片段没有布局权重)

顺便说一下,片段完全包含在框架布局中。框架布局刚刚被原始布局中的广告片段重叠。上述建议使其不存在重叠


希望这有帮助。

如果您希望避免重叠并使容器填满屏幕,那么您应该将RelativeLayout更改为LinearLayout

 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame"
    android:orientation:"vertical"
    >
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"  />
    <fragment
        android:id="@+id/adFragment"
        android:name="com.jiyuzhai.wangxizhishufazidian.MainActivity$AdFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

谢谢,添加这一行后工作
android:layout_over=“@id/adFragment
 <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        tools:ignore="MergeRootFrame">
        <fragment
            android:id="@+id/adFragment"
            android:name="com.jiyuzhai.wangxizhishufazidian.MainActivity$AdFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/adFragment" />
</RelativeLayout>
 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame"
    android:orientation:"vertical"
    >
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"  />
    <fragment
        android:id="@+id/adFragment"
        android:name="com.jiyuzhai.wangxizhishufazidian.MainActivity$AdFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>