Reputation: 395
I have an activity with a TextView. I would like to align it on the bottom of the screen, in the center and I would like that the TextView fits the screen's width.
This is my XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#ffffff"
tools:context=".ShowCard" >
<TextView
android:id="@+id/textView"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#33000000"
android:textColor="#000000"
android:text="@string/lorem_ipsum" />
The result is not what I have expected to see. The TextView is not full-screen in the width, but leaves a small free space right and left (like padding/border, but I've not set padding/border!).
Do you know why? Suggestions?
Upvotes: 4
Views: 3851
Reputation: 395
Excuse me, I'm a stupid guy! I've not see that in the container XML code were included four padding rows:
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
I've deleted these rows and now everything is working correctly!
Sorry.
Upvotes: 3
Reputation: 1351
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context=".ShowCard" >
<TextView
android:id="@+id/textView"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#33000000"
android:textColor="#000000"
android:text="@string/lorem_ipsum" />
use this
Upvotes: 0
Reputation: 1844
remove
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
from the parent relative layout.
Upvotes: 0
Reputation: 780
<TextView
android:id="@+id/textView"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#33000000"
android:textColor="#000000"
android:text="@string/lorem_ipsum" />
Use the 'fill_parent' attribute, it should fill the entire width of the screen.
Upvotes: 0
Reputation:
try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#33000000"
android:textColor="#000000"
android:text="@string/lorem_ipsum" />
</RelativeLayout>
Upvotes: 4