The Dude
The Dude

Reputation: 1118

How can I place Button or TextView at the absolute bottom in RelativLayout?

There seems to be some hidden padding in the RelativLayout, I'm I right?

I've got this TextView:

    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/green"
    android:text="LOG IN"/>

in a RelativeLayout.

What I cant understand is why

    android:layout_alignParentBottom="true"

doesn't place the TextView all the way down. ref image:

enter image description here

Is there any way to remove this padding?

Upvotes: 2

Views: 176

Answers (3)

Quick learner
Quick learner

Reputation: 11457

Use this code and do let me know if you find any problem ... thanks

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp" >

<ImageView
    android:id="@+id/picture"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop" />

<TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/picture"
    android:layout_gravity="bottom"
    android:background="@drawable/grid_text_back"
    android:paddingBottom="15dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="15dp"
    android:textColor="@android:color/white"
    android:textStyle="bold" />

Upvotes: 0

Tang Yun
Tang Yun

Reputation: 159

Here the TextView's parent is the Entire RelativeLayout.

TextView is indeed at RelativeLayout's Bottom, but doesn't mean that RelativeLayout's bottom is aligned with the screen's absolute bottom.

Try set android:layout_marginBottom = "0px" for your RelativeLayout.

BTW, padding is used between Layout and its Views inside, margin is used outside between Layout and screen borders

Upvotes: 0

The Dude
The Dude

Reputation: 1118

The solution to my question was very easy and provided by @Marco Dufal.

Go in the dimens.xml in the res/values folder and set the margin to 0dp:

<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>

Upvotes: 1

Related Questions