K.Muthu
K.Muthu

Reputation: 1252

Alignment issue in text view Android

I have two text views to display the text one below other. The issue i face is when the text size in the above text view is lengthy it affects the below text view as the text display over the other . I have the image and the code i used is as below. Can any one find a solution for this .. thanks in advance

Image:

enter image description here

Code:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@android:style/Theme.Panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
>

<TextView
    android:id="@+id/title"
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="15dp"
    android:ellipsize="end"
    android:textColor="#000000"
    android:textSize="25sp"
    android:textStyle="normal" />

<TextView
    android:id="@+id/tamil"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/title"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="10dp"
    android:textColor="#000000"
    android:textSize="25px"
    android:textStyle="bold" />

<TextView
    android:id="@+id/english"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/tamil"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/tamil"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="30dp"
    android:textColor="#000000"
    android:textSize="25px"
    android:textStyle="normal" />
   </RelativeLayout>

Upvotes: 1

Views: 217

Answers (3)

Padma Kumar
Padma Kumar

Reputation: 20041

in your English text view add like this

<TextView    android:id="@+id/english"
android:layout_below="@id/tamil"

//and remove this attribute also

 android:layout_alignLeft="@+id/tamil"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/tamil"

dont use @+id for reference its already you defined. dont use px for your font size use sp as you did it for title.

Upvotes: 1

Praveenkumar
Praveenkumar

Reputation: 24506

Just include android:layout_below="..." into your english TextView like below -

<TextView
android:id="@+id/english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tamil"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:textColor="#000000"
android:layout_below="@+id/tamil" // this line
android:textSize="25px"
android:textStyle="normal" />

and remove android:layout_alignTop="@+id/tamil"

Upvotes: 1

Aerilys
Aerilys

Reputation: 1639

You can regroup the two of them inside a LinearLayout with vertical orientation. It should solve your problem.

Upvotes: 2

Related Questions