Reputation: 1217
I have two TextViews in LinearLayout. Layout orientation is in horizontal. I have to maintain both Textview height as equal. But as per text length both are shown in different height.
I had tried to make the same text length like below
public static String padRight(String s, int n) {
return String.format("%1$-" + n + "s", s);
}
But height is bit different. How do i solve this ?
Upvotes: 2
Views: 1182
Reputation: 15533
If I didn't misunderstand you you want to TextView
s inside a horizontal oriented LinearLayout
, and both TextView
s must in same height.
Then use a layout something like below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#B40431"
android:text="text sample\ntext sample\ntext sample\ntext sample\ntext sample\ntext sample\n"
android:gravity="center_vertical"/>
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000FF"
android:text="text sample\ntext sample\ntext sample"
android:gravity="center_vertical"/>
</LinearLayout>
Output is going to be this:
Upvotes: 3
Reputation: 3513
Because the text is long textview getting bigger So You set the singleLine true of your textView then it will work,
Add this line in your Textview xml:--
android:singleLine="true"
hope it helps you..
Upvotes: 1