-1

I was trying to make an interface that allows horizontal texts to be equally space, using layout_weight for responsiveness

So, I tried the code below

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="@android:color/darker_gray">

<TextView
    android:gravity="center"
    android:text="Guest List"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="24sp"
    android:background="@android:color/holo_blue_bright"/>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
    <TextView
        android:text="Kunal"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="24sp"/>


    <TextView
        android:text="Darling"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="24sp"/>

    <TextView
        android:text="Shocker"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="24sp"/>
</LinearLayout>

However, all the texts disappear. So, could anyone please kindly explain to me what happened and how to fix this problem?

  • **1** - Format your code. **2** - Did you close the external LinearLayout? **3** - How do you fill the TextViews? I see no text in them. – Phantômaxx Jul 04 '15 at 20:38
  • **4** - You could avoid `layout nesting` (bad for performances), by using a RelativeLayout. The **easier** way is not always the **preferred** one. – Phantômaxx Jul 05 '15 at 11:05

2 Answers2

1

Try this,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray"
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_blue_bright"
        android:gravity="center"
        android:text="Guest List"
        android:textSize="24sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Kunal"
            android:textSize="24sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Darling"
            android:textSize="24sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Shocker"
            android:textSize="24sp" />
    </LinearLayout>

</LinearLayout>
Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50
0

Using a white background color in the second LinearLayout, you may be trying to see white on white text.

I'd try to add to the TextViews something along:

        android:textColor="@android:color/black"
Stéphane
  • 6,920
  • 2
  • 43
  • 53