AdView Banner внутри вкладок Активность - PullRequest
0 голосов
/ 13 октября 2018

Я пытаюсь показать баннерную рекламу внутри линейного макета, в которой есть вкладки (фрагменты).

Но что бы я ни пытался, рекламный баннер не появляется.Вот мой код:

XML:

activity_hometopnav.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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_hometabs"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.vossenthemes.swappuser.activities.homepages.HomeTopNavActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbarlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.TabLayout
        android:id="@+id/top_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:tabSelectedTextColor="@android:color/white"
        app:tabIndicatorColor="@color/colorAccentLight"
        app:tabGravity="fill"
        app:tabTextColor="@color/colorAccentLight"
        />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom|center"
        ads:adSize="BANNER"
        ads:adUnitId="@string/admob_banner_id">
    </com.google.android.gms.ads.AdView>

</LinearLayout>

фрагмент_home.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"
    xmlns:ads="http://schemas.android.com/apk/res-auto">


    <android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    </android.support.v4.widget.SwipeRefreshLayout>

    <FrameLayout
        android:id="@+id/frameLayout"
        android:background="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="3dp">

        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:background="@android:color/transparent"
            android:progressDrawable="@drawable/progress_color"
            android:id="@+id/progressBar"
            android:layout_width="match_parent"
            android:layout_height="8dp"
            android:layout_marginTop="-3dp"
            android:layout_gravity="top"
            android:max="100"
            android:progress="20"/>

    </FrameLayout>

JAVA:

HomeTopNavActivity.java

 MobileAds.initialize(this, getString(R.string.admob_banner_id));
 bannerAd = findViewById(R.id.adView2);
 bannerAd.loadAd(adRequest);

Я пытаюсь показать баннерную рекламу внутри линейного макета, в которой есть вкладки (фрагменты).

Но что бы я ни пытался, рекламный баннер не 'не показывай.

1 Ответ

0 голосов
/ 13 октября 2018

Высота вашего Viewpager равна match_parent.Так что нет места для рекламы.Вы можете использовать Android: layout_weight для этой проблемы.Например:

  <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

  <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView2"
        android:layout_width="wrap_content"
        android:layout_height="64dp"       <--- You can change height
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom|center"
        ads:adSize="BANNER"
        ads:adUnitId="@string/admob_banner_id">
  </com.google.android.gms.ads.AdView>
...