2014-02-05 100 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