2014-02-05 50 views
0

我無法正確發佈admob在帶有頂部的Progressbar的LinearLayout中的webview。我嘗試了很多方法,使用Relatives,並在Stackoverflow中搜索並執行一些步驟,但此Progressbar將無法工作。Webview + admob在底部+ LinearLayout

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <ProgressBar 
      android:id="@+id/ProgressBar" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:indeterminate="false" 
      android:maxHeight="10dip" 
      android:minHeight="10dip" 
      android:progress="50" 
      android:progressDrawable="@drawable/greenprogress" /> 

     <WebView 
      android:id="@+id/webview" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
    </LinearLayout> 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     ads:adSize="BANNER" 
     ads:adUnitId="ca-app-pub-7041222655570180/1503313077" 
     ads:loadAdOnCreate="true" 
     ads:refreshInterval="30" > 
    </com.google.ads.AdView> 

</LinearLayout> 

回答

3

您發佈的佈局將無法工作,因爲你內心的線性佈局有wrap_content高度(從而導致其孩子的layout_weight s到可以忽略),但Web視圖具有0您也給了廣告的高度查看1的重量,好像它應該抓取儘可能多的空間,通常廣告應該有固定的高度。

我不確定爲什麼RelativeLayout不適合你,但也許你試圖與layout_weight一起使用它?如果是這樣,請注意layout_weight僅適用於LinearLayout的子項。

這裏是我會怎麼做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentTop="false" 
     android:layout_centerHorizontal="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="ca-app-pub-7041222655570180/1503313077" 
     ads:loadAdOnCreate="true" 
     ads:refreshInterval="30" > 
    </com.google.ads.AdView> 

    <LinearLayout 
     android:layout_alignParentTop="true" 
     android:layout_above="@id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <ProgressBar 
      android:id="@+id/ProgressBar" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:indeterminate="false" 
      android:progress="50" 
      android:progressDrawable="@drawable/greenprogress" /> 

     <WebView 
      android:id="@+id/webview" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
    </LinearLayout> 


</RelativeLayout> 
+0

非常感謝你Tenfour,它的工作! :-) – David

+0

就像我的魅力一樣。我敬禮。 –

+0

我對使用Fragments展示廣告有疑問。 ([link](https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start))。如果沒有互聯網連接,內容是否會延伸並填滿屏幕? – user2731584