Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position a TextView in a layout in Android?

I want to design this kind of layout, which will have a title and a background image as shown in the below image, and three TextViews at the center of each separator. When one of the TextViews text size increases, the other TextViews will remain at the same position.

enter image description here

How can I achieve this?

like image 453
KousiK Avatar asked Dec 25 '22 17:12

KousiK


1 Answers

You can try the following code:

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="TextView" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="TextView" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="TextView" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="TextView" />
    </LinearLayout>

</LinearLayout>
like image 53
Kaushik Avatar answered Dec 31 '22 14:12

Kaushik