Setting a view in Bottom

0

Currently I use this code to put Adview in Bottom, but when adding a ScrollView, it is fixed at the bottom of the list and not at the bottom of the screen.

-

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        android:id="@+id/ScrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

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

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/android" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="bosa" />

            <Button
                android:id="@+id/btsair"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="Sair" />
        </LinearLayout>
    </ScrollView>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="1357125518" />

</RelativeLayout>
    
asked by anonymous 01.09.2014 / 03:17

1 answer

1

When you use ScrollView , the use of match_parent is different than ViewGroup .

As quoted by Romain Guy , a former AOSP developer, ScrollView has a different dynamic than the other ViewGroups in relation to the content that is inside.

Without using the fillViewPort flag, it is as if the layout_height of ScrollView rule is always wrap_content regardless of the height of the content it is in.

When using fillViewPort="true" , ScrollView forces the height of the first child (the only direct child) to be match_parent relative to the ScrollView parent. I'll try to explain it better with an example.

Using your layout with the fillViewPort="true" flag will be:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/ScrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"> <!-- Flag necessaria -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFFFFF"
            android:orientation="vertical" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/ab_bottom_solid_ab" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="bosa" />

            <Button
                android:id="@+id/btsair"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="Sair" />
        </LinearLayout>

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="71684724/135" />

    </RelativeLayout>
</ScrollView>

When you do not use fillViewPort="true" , we already know that RelativeLayout will occupy the minimum height required to contain your layout. Soon your AdView will not go to the bottom of the screen.

Using fillViewPort="true" , ScrollView forces RelativeLayout to have height layout_height="match_parent" relative to the parent of ScrollView , which is FrameLayout of its Activity .     

02.09.2014 / 01:13