TextView height does not match_parent / fill_parent

3.8k views Asked by At

I have a simple TextView with a singleLine. I would like to set the height to match_parent/fill_parent, but the behaviour of Android is to only to wrap_content.

Is there a way to force that the TextView takes all height ?

Tkx

Edit :

This is what I get :

enter image description here and my layout :

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

<TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:paddingLeft="13dp"
        android:paddingRight="3dp"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

        [...]

</RelativeLayout>
2

There are 2 answers

0
sowjanya On

For that TextView parent width, you may use wrap_content.

0
Debarati On

You can set the TextView height to match_parent/fill_parent. And change the gravity and all other property of that TextView according to your requirement.

If this is not suffiecient for you then let me know what exactly you want to do.

EDIT:

As per your new edited code i worked on your code.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" 
android:layout_width="match_parent">
<TextView android:id="@+id/date" 
    android:layout_width="wrap_content"
    android:layout_height="match_parent" 
    android:gravity="center"
    android:paddingLeft="13dp" 
    android:paddingRight="3dp"
    android:textStyle="bold" 
    android:textColor="#ffffff" 
    android:text="dateText"/>
</RelativeLayout>

Now its showing the TextView at the central_vertical position of the whole screen.

Try this code. Its working. Change your RelativeLayout and TextView as i did with these.