0

So I have created a layout that is a row of 3 textviews. What I am trying to achieve is to have the first text view a lot wider than the other two text views.

I have tried setting the layout_width to values like 32dp etc but that seems to effect the other text views and the height as well.

So this is what it looks like now enter image description here

and here is the code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/colum1"
        android:layout_width="62dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        android:text="TextView"
        android:textSize="18sp"
        android:textColor="#ff000000" />
    <TextView
        android:id="@+id/colum2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        android:text="TextView"
        android:textSize="18sp"
        android:textColor="#ff000000" />
    <TextView
        android:id="@+id/colum3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        android:text="TextView"
        android:textSize="18sp"
        android:textColor="#ff000000" />
</LinearLayout>

I would Like for possibly textview colum1 to take up the width of the first two text views and the last two to be the widh of one.

Like This enter image description here

Michael Grinnell
  • 922
  • 1
  • 12
  • 32
  • @grrigore that solved my problem Thank you – Michael Grinnell Aug 16 '18 at 15:34
  • your XML is perfect you just change android:layout_weight="1" to this order. **For Bigger TextView android:layout_weight="0.4"** **For Smaller TextView android:layout_weight="0.2"** **For Smaller TextView android:layout_weight="0.1"** – Arbaz.in Aug 17 '18 at 10:32

2 Answers2

2

Try this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/colum1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        android:text="TextView"
        android:textSize="18sp"
        android:textColor="#ff000000" />
    <TextView
        android:id="@+id/colum2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        android:text="TextView"
        android:textSize="18sp"
        android:textColor="#ff000000" />
    <TextView
        android:id="@+id/colum3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        android:text="TextView"
        android:textSize="18sp"
        android:textColor="#ff000000" />
</LinearLayout>

This is the result:

enter image description here

More info here.

grrigore
  • 1,050
  • 1
  • 21
  • 39
1

You will want to remove the weight from the first TextView, either that, or set it's weight to 2. Read more on the Android docs here: https://developer.android.com/guide/topics/ui/layout/linear

Zeke Hernandez
  • 1,226
  • 11
  • 14