Alex
Alex

Reputation: 3

TextView text is not displayed

I am using Relative Layout to display ImageView and TextView. But default text assigned to TextView is not displayed, please check below Xml code:

<?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">

    <ImageView
        android:id="@+id/backgroundImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/background" />
    <RelativeLayout
        android:background="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="100dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/trainName"
            android:textAlignment="center"
            android:background="#F81A07"
            android:textColor="#1BADEE"
            android:text="Default Text"
            android:textSize="20sp"
            android:padding="100dp"
            android:layout_alignParentBottom="true"/>


    </RelativeLayout>
</RelativeLayout>

Upvotes: 0

Views: 279

Answers (5)

Gayathri
Gayathri

Reputation: 249

Ya, The fluffy Robot's point is correct, Check it and change it.

<?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">

    <ImageView
        android:id="@+id/backgroundImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/background" />
    <RelativeLayout
        android:background="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/trainName"
            android:textAlignment="center"
            android:background="#F81A07"
            android:textColor="#1BADEE"
            android:text="Default Text"
            android:textSize="20sp"
            android:padding="2dp"
            android:layout_alignParentBottom="true"/>


    </RelativeLayout>
</RelativeLayout>

Upvotes: 0

Android Geek
Android Geek

Reputation: 9225

I have try your xml code . there is one minor problem android:padding="100dp"

remove it from text view . please sure about that layout height and child view padding are should not same.

this is my xml code try this:

with padding

<RelativeLayout
    android:background="#ffffff"
    android:layout_width="match_parent"
    android:layout_height="100dp">


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/trainName"
android:text="Default Text"
android:textAlignment="center"
android:background="#F81A07"
android:textColor="#1BADEE"
android:textSize="20sp"
android:padding="40dp"/>
    </RelativeLayout>

Without padding

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="#ffffff">


    <TextView
        android:id="@+id/trainName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#F81A07"
        android:text="Default Text"
        android:textAlignment="center"
        android:textColor="#1BADEE"
        android:textSize="20sp" />

</RelativeLayout>

I hope its work for you

Upvotes: 0

Rashmi patel
Rashmi patel

Reputation: 31

I tried your code and yes you have set wrong attribute android:padding="100dp".

Here is your code:

<TextView
            android:id="@+id/trainName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#F81A07"
            android:text="Default Text"
            android:textAlignment="center"
            android:textColor="#1BADEE"
            android:textSize="20sp"
            android:visibility="visible" />

I am agree with The Fluffy Robot's answer.

Happy Coading !!

Upvotes: 0

The Fluffy Robot
The Fluffy Robot

Reputation: 459

Within your inner RelativeLayout you have the attribute android:layout_height="100dp" which will make the RelativeLayout have a height of 100dp.

Within the TextView that resides inside that view, you have the attribute android:padding="100dp" which will add 100dp padding on all sides of the TextView which pushes it just outside the borders of the RelativeLayout.

Try adjusting the height of the inner RelativeLayout or reducing the padding of the TextView.

Upvotes: 1

Nikhil Vadoliya
Nikhil Vadoliya

Reputation: 1588

You should be remove android:layout_alignParentBottom="true" is TextView

Upvotes: 0

Related Questions