1

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.

joeldroid
  • 155
  • 1
  • 9

2 Answers2

4

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

Community
  • 1
  • 1
N J
  • 27,217
  • 13
  • 76
  • 96
0

You can use 3 RelativeLayouts with respective weights inside a LinearLayout of horizontal orientation.

DarshanGowda0
  • 452
  • 3
  • 11