Search code examples
androidlayoutandroid-linearlayout

Android Layout 3 Items With Different Widths In Same Line


I would like to know how I can put 3 different elements with different widths in the same line?

Like below

LinearLayout with Horizontal orientation (parent) within that, Textview(50% width-align left)ImageView(25% width-align right)Textview(25% width-align right) all in the same line?

Please help.


Solution

  • You can use LinearLayout with weight

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/activity_landing"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.50"
            android:text="1" />
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:text="2" />
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:text="3" />
    </LinearLayout>
    

    Or

    You can use PercentRelativeLayout see this answer