Setting a view at the bottom

Asked

Viewed 484 times

0

Currently I use this code to put Adview in the 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>
  • 4

    Josinaldo, include the layout xml if you can, it’s easier to understand the situation.

1 answer

1

When you wear one ScrollView, the use of match_parent is different than in a ViewGroup.

Like quoted by Romain Guy, a former AOSP developer, the ScrollView has a different dynamic from the others ViewGroups in relation to the content within.

Without the use of the flag fillViewPort, is as if the rule of layout_height of ScrollView were always wrap_content regardless of the height of the content inside.

When using the fillViewPort="true", the ScrollView the height of the first child (the only direct child) is match_parent in relation to the father of ScrollView. I’ll try to explain it better with an example.

Using your flag layout fillViewPort="true", will stay:

<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 don’t use the fillViewPort="true", we already know that the RelativeLayout will occupy the minimum height necessary to contain your layout. Soon your AdView will not go to the background of the screen.

Using fillViewPort="true", the ScrollView force that the RelativeLayout be tall layout_height="match_parent" in relation to the father of ScrollView, which is the FrameLayout of his Activity.

  • I have little knowledge about layout, I understood step by step what Voce wrote most when applied did not return me change. (I changed the code with the scrollview within the relative, I think it is more coherent..)

  • Okay, I’ll review the solution with the layout change.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.