David
David

Reputation: 383

Webview + admob in bottom + LinearLayout

I'm unable to publish correctly admob in the botton with a webview in LinearLayout with a Progressbar in the top. I tried many ways, with Relatives, and search in Stackoverflow and follow some steps, but this Progressbar won't work.

    <?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>

Upvotes: 0

Views: 2418

Answers (1)

Tenfour04
Tenfour04

Reputation: 93759

Your posted layout won't work because your inner linear layout has a height of wrap_content (thereby causing its children's layout_weights to be ignored) but the web view has a height of 0. You also gave your ad view a weight of 1, as if it should grab as much space as possible, when normally an ad should have a fixed height.

I'm not sure why RelativeLayout didn't work for you, but maybe you were trying to use it with layout_weight? If so, note that layout_weight only applies to the children of a LinearLayout.

Here is how I would do it:

<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>

Upvotes: 3

Related Questions