Question

I have a Layout for Android app with few buttons in it. I am trying to set an Ad at the bottom of the page. Please refer to my layout below:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/MainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_color"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/adView"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_top_margin" >

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

            <TextView
                android:id="@+id/textView0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left|center_vertical"
                android:text=""
                android:textColor="@color/text_color"
                android:textSize="@dimen/nav_text_size" >
            </TextView>

            <Button
                android:id="@+id/ProceedToScreen31"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_action_name"
                android:gravity="left|center_vertical"
                android:text="@string/TA1"
                android:textColor="@color/btn_text_color"
                android:textSize="@dimen/button_text_size" >
            </Button>

            <Button
                android:id="@+id/ProceedToScreen32"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_action_name"
                android:gravity="left|center_vertical"
                android:text="@string/TA2"
                android:textColor="@color/btn_text_color"
                android:textSize="@dimen/button_text_size" >
            </Button>

            <Button
                android:id="@+id/ProceedToScreen33"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_action_name"
                android:gravity="left|center_vertical"
                android:text="@string/TA3"
                android:textColor="@color/btn_text_color"
                android:textSize="@dimen/button_text_size" >
            </Button>

            <Button
                android:id="@+id/ProceedToScreen34"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_action_name"
                android:gravity="left|center_vertical"
                android:text="@string/TA4"
                android:textColor="@color/btn_text_color"
                android:textSize="@dimen/button_text_size" >
            </Button>

            <View
                android:layout_width="match_parent"
                android:layout_height="2dip"
                android:background="@color/line_color" >
            </View>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/copyright"
                android:textColor="@color/text_color"
                android:textSize="@dimen/small_text_size" >
            </TextView>
        </LinearLayout>
    </ScrollView>

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/MY_AD_UNIT_ID"
        ads:loadAdOnCreate="true" />

</RelativeLayout>

The Ad is perfectly coming to the bottom of the page as fixed footer (As per my requirement) but along with that other components of the page are also coming to the bottom of the page leaving, big space at the top of the page. PLease help How can I align so that Only Ad should come to the bottom of the page, rest all components should start from the top of the page.

Was it helpful?

Solution 4

Thanks guys for your inputs, there was problem with my code, I was setting Ad with Java class as well as in the XML file both places, I removed the Ad code in Java and changed little bit of code in XML file as per suggestions here android:layout_above="@+id/adView"

Now everything looks fine and as per requirement. Thanks again for your time and inputs.

OTHER TIPS

It's because of this line in the scroll view:

android:layout_above="@+id/adView"

It's doing that because you're basically telling it, "Just above the adView, put the ScrollView." Just removing that fixed it for me.

Try removing

android:gravity="center_horizontal"

from the top layout. Actually, I would remove all references to gravity until you have things in the right place, personally. Also, you might want to check how large

@dimen/activity_top_margin

is. It may well explain the space you have.

Add to the ScrollView -> android:layout_alignParentTop="true" and this will remove the blank space on the top.

In addition, I would suggest to set the AdView first and then set the ScrollView with android:layout_above="@+id/adView" because ScrollView sets its layout accordingly to the AdView and sometimes it is required to define first the layout that doesn't relies on any other layout and then define other layouts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top