AdView не показывает рекламу в нижней части линейного макета. Почему? - PullRequest
0 голосов
/ 09 июня 2019

Я пытаюсь показать AdMob AdView в нижней части экрана, но это не работает. Под текстом отображается объявление, если текст короткий (не нужно прокручивать), но если текст длинный (нужно прокручивать), объявление вообще не показывается. Я хочу, чтобы объявление показывалось внизу экрана независимо от того, насколько длинным или коротким является текст. Я занимался этим часами, но не мог понять, как это работает.

Вот мой Activity.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:background="@color/backgroundColor"
    tools:context=".activities.DetailActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:elevation="1.46dp"
        android:background="@color/backgroundColor">

        <TextView
            android:id="@+id/tvWordDetail"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textColor="@color/textColorPrimary"
            android:textSize="20sp"
            android:gravity="center_vertical"/>

        <ImageButton
            android:id="@+id/textToSpeech"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:contentDescription="@string/text_to_speech"
            android:background="?actionBarItemBackground"
            app:srcCompat="@drawable/ic_volume"/>

        <ImageButton
            android:id="@+id/btnBookmark"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:contentDescription="@string/add_bookmark"
            android:background="?actionBarItemBackground"
            app:srcCompat="@drawable/ic_bookmark_border"/>

    </LinearLayout>

    <View
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/viewColor"/>

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/backgroundColor"
            android:elevation="1.46dp"
            android:orientation="vertical"
            android:paddingLeft="16dp"
            android:paddingTop="10dp"
            android:paddingRight="16dp">


            <TextView
                android:id="@+id/tvWordDefinition"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:textColor="@color/textColorSecondary"
                android:textSize="18sp" />

        </LinearLayout>

    </ScrollView>

    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adViewDetail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/admob_banner_ad_detail">

    </com.google.android.gms.ads.AdView>

</LinearLayout>

Ответы [ 2 ]

0 голосов
/ 09 июня 2019

Попробуйте этот код


<?xml version="1.0" encoding="utf-8"?>
<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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="680dp"
        android:orientation="vertical"
        android:background="@color/backgroundColor" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"

            android:background="@color/backgroundColor">

            <TextView
                android:id="@+id/tvWordDetail"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:textColor="@color/textColorPrimary"
                android:textSize="20sp"
                android:gravity="center_vertical"/>

            <ImageButton
                android:id="@+id/textToSpeech"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="?actionBarItemBackground"
                app:srcCompat="@drawable/ic_volume"/>

            <ImageButton
                android:id="@+id/btnBookmark"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:contentDescription="@string/add_bookmark"
                android:background="?actionBarItemBackground"
                app:srcCompat="@drawable/ic_bookmark_border"/>

        </LinearLayout>


        <ScrollView
            android:id="@+id/scrollView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/backgroundColor"
                android:elevation="1.46dp"
                android:orientation="vertical"
                android:paddingLeft="16dp"
                android:paddingTop="10dp"
                android:paddingRight="16dp">


                <TextView
                    android:id="@+id/tvWordDefinition"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@color/textColorSecondary"
                    android:textSize="18sp" />

            </LinearLayout>

        </ScrollView>
    </LinearLayout>




    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adViewDetail"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/admob_banner_ad_detail">

    </com.google.android.gms.ads.AdView>

</LinearLayout>
0 голосов
/ 09 июня 2019

Добавьте один новый атрибут android: layout_weight = "1" и измените высоту представления прокрутки, как показано ниже.

    android:layout_height="0dp"
    android:layout_weight="1"

Итак, окончательный набор атрибутов scrollview выглядит так,

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">
...