Android RelativeLayout: How to put a view above another view, without necessarily touching?

10,553

Solution 1

This seems a bit weird, but here's how I got it working. Since the text at the bottom is of size "8dip", and takes up either 1 or 2 lines depending on screen orientation, I put a padding of "16dip" below the list.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@color/blue">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/details_wrapper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:paddingBottom="16dip">
        <ListView 
            android:id="@+id/table" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:background="@drawable/white_box">
        </ListView>
    </LinearLayout>

<TextView
    android:id="@+id/fine_print"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"  
    android:gravity="center_horizontal"
  />
</RelativeLayout>

Still open to suggestions on making this cleaner, though.

Solution 2

Answering the topic: view.bringToFront();

You can also try in xml this: android:translationZ="10dp"

Solution 3

I think you can resolve your issue by simply adding to your TextView something like

android:layout_below:"@+id/table"

Let me know if ot works.

Share:
10,553
Kalina
Author by

Kalina

Updated on June 04, 2022

Comments

  • Kalina
    Kalina almost 2 years

    I am displaying a ListView that can have any number of rows. I want the ListView to wrap the content. I also want some text to be at the bottom of the screen, regardless of the size of the list. Like so:

    What I want to happen

    My attempt at making this happen is below, but when the content is large, it causes it to look like the bottom left image.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="@color/blue">
        <TextView
            android:id="@+id/fine_print"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"  
            android:layout_below:"@+id/table"
            android:gravity="center_horizontal"
          />
        <ListView 
            android:id="@+id/table" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:background="@drawable/white_box">
        </ListView>
    </RelativeLayout>
    

    And adding

    android:layout_above="@id/fine_print"
    

    to @id/table makes it look like the bottom right image.

    What ends up happening

    How can I make it do what I want?

  • Kalina
    Kalina over 11 years
    No, that also causes the text on bottom to be pushed off screen, like the bottom left image.
  • lschlessinger
    lschlessinger over 9 years
    Were you ever able to find a cleaner solution to this?
  • Imran Ahmed
    Imran Ahmed almost 9 years
    @Kalina + yugidroid solution works. use this xml and add android:layout_below:"@+id/table" will work for you
  • Imran Ahmed
    Imran Ahmed almost 9 years
    Kalina + @yugidroid solution works. use this xml and add android:layout_below:"@+id/table" will work for you