Search code examples
androidandroid-studioalignment

Android Studio: Alignment


I've a problem with alignment a webview and an AdView in Android Studio:

What I want to get, is the ad at the bottom and all over it the webview. However, I am not able to resize the webwiev to start from the top. At the moment, the webview is just as big as the website is, as you can see here: https://www.dropbox.com/s/bkj00jnck049kqm/Unbenannt.png

Here's my xml layout code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="0dp"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="bottom">

        <WebView
            android:id="@+id/activity_main_webview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/ad_view"
            />

        <com.google.android.gms.ads.AdView
            android:id="@+id/ad_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
        />

    </LinearLayout>

</RelativeLayout>

Solution

  • Use android:layout_alignParentBottom="true" in your AdView

    SAMPLE CODE

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="0dp"
        tools:context=".MainActivity"
        tools:ignore="MergeRootFrame">
    
    
        <WebView
            android:id="@+id/activity_main_webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <com.google.android.gms.ads.AdView
            android:id="@+id/ad_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
    
    
    </RelativeLayout>