Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.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 将横幅广告放置在带有碎片的父项底部_Android_Admob_Fragment_Banner - Fatal编程技术网

Android 将横幅广告放置在带有碎片的父项底部

Android 将横幅广告放置在带有碎片的父项底部,android,admob,fragment,banner,Android,Admob,Fragment,Banner,我正在制作一个android应用程序,但在定位横幅时遇到了麻烦 我有一个活动充当片段的容器。我基本上想要一个根的滚动视图,然后是片段和底部的广告 这是我的XML <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android

我正在制作一个android应用程序,但在定位横幅时遇到了麻烦

我有一个活动充当片段的容器。我基本上想要一个根的滚动视图,然后是片段和底部的广告

这是我的XML

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"></LinearLayout>

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:layout_constraintBottom_toBottomOf="parent"
            ads:layout_constraintStart_toStartOf="parent"
            ads:layout_constraintEnd_toEndOf="parent"
            ads:layout_constraintTop_toBottomOf="@id/fragment_container"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-xxxx"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>



使用以下代码更改xml

<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:fillViewport="true"
        android:layout_weight="1">

        <androidx.appcompat.widget.LinearLayoutCompat
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />

    </ScrollView>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-xxxx" />

</androidx.appcompat.widget.LinearLayoutCompat>

我希望这能帮助你


谢谢。

使用以下代码更改xml

<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:fillViewport="true"
        android:layout_weight="1">

        <androidx.appcompat.widget.LinearLayoutCompat
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />

    </ScrollView>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-xxxx" />

</androidx.appcompat.widget.LinearLayoutCompat>

我希望这能帮助你


谢谢。

尼斯问候您!你能用RelativeLayout;)试试吗


尼斯向你致意!你能用RelativeLayout;)试试吗


您可以使用相对布局进行此操作:

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

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:id="@+id/fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" />


        </ScrollView>

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-xxxx"
            android:layout_alignParentBottom="true"/> <!--just add this line-->

    </RelativeLayout>

您可以使用相对布局进行此操作:

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

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:id="@+id/fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" />


        </ScrollView>

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-xxxx"
            android:layout_alignParentBottom="true"/> <!--just add this line-->

    </RelativeLayout>


你能使用相对布局吗?@Karan-用相对布局替换包含碎片容器+ad的约束布局会产生相同的结果。如果你想要@smallgrammer,我可以用相对布局添加答案,这会有助于澄清。你能用相对布局吗?@Karan-替换约束布局使用相对布局包含片段容器+ad会产生相同的结果。如果您需要@smallgrammer,我可以使用相对布局添加答案,这将有助于澄清。我感谢您的努力:)这就是为什么投票!!英雄联盟祝你下次好运;)我很感激你的努力:)这就是为什么投票吧!!英雄联盟祝你下次好运;)@你要试试这个吗?@你要试试这个吗?
<?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:id="@+id/fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" />


        </ScrollView>

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-xxxx"
            android:layout_alignParentBottom="true"/> <!--just add this line-->

    </RelativeLayout>