在LinearLayout中的网页视图下方放置adMob的问题

时间:2016-05-07 08:37:57

标签: android android-layout android-studio admob

在过去的五天里,我试图将google adob放在webView上。我错过了什么,请帮忙。如果广告显示它占据整个窗口并隐藏所有内容。

<?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:ads="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/app_bar_main"
        tools:context=".MainActivity"
        android:weightSum="1"
        android:orientation="horizontal">


        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="75dp"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id"
            android:clickable="false"
            android:visibility="visible">
        </com.google.android.gms.ads.AdView>

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>

        <WebView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:id="@+id/webView"
            android:layout_weight="0.97" />


    </LinearLayout>

Java代码:

AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

输出: enter image description here

2 个答案:

答案 0 :(得分:1)

使用此xml而不是xml .....

xml中有6到7个更改

<?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:ads="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/app_bar_main"
        tools:context=".MainActivity"
        android:weightSum="1"
        android:orientation="vertical">

        <WebView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/webView"
            android:layout_weight="0.90" />


        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"/>


        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_weight="0.10"
            android:layout_height="0dp"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id"
            android:visibility="visible">
        </com.google.android.gms.ads.AdView>


    </LinearLayout>

享受编码..........

答案 1 :(得分:1)

你应该使用RelativeLayout,就像这样

<RelativeLayout
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">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/myId"
    android:orientation="vertical">

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>
    <WebView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/webView"
        android:layout_weight="0.97" />

</LinearLayout>
<com.google.android.gms.ads.AdView
    android:id="@+id/myId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="" />
</RelativeLayout>