代码之家  ›  专栏  ›  技术社区  ›  Shahid Karimi

在LinearLayout中将adMob放置在web视图下方时出现问题

  •  -1
  • Shahid Karimi  · 技术社区  · 10 年前

    在过去的五天里,我试图将google admob放在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 回复  |  直到 10 年前
        1
  •  3
  •   sushildlh    10 年前

    使用此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>
    

    享受编码。。。。。。。。。。

        2
  •  1
  •   abdoulayeYATERA    10 年前

    你应该像这样使用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>