George Irimiciuc
George Irimiciuc

Reputation: 4633

Textview not showing

I have a linearlayout and a textview inside another linearlayout. The linearlayout from inside is displayed, but the problem is that the last textview is not. Why?

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:padding="10dp"
        android:text="Scrie un cuvant" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/cuvant"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="@string/cuvant_hint"
            android:inputType="text" />

        <Button
            android:id="@+id/cuvantbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cuvantbutton_text" />
    </LinearLayout>


        <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:padding="10dp"
        android:text="Sau random" />
</LinearLayout>

Have a look here,

enter image description here

Upvotes: 7

Views: 39082

Answers (5)

Anvesh Bemore
Anvesh Bemore

Reputation: 9

The parent layout must cover the textview, to get text in it.

The layout with problem,which does not diplay text-----------

<LinearLayout
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/Crime">

        </ImageView>

        <LinearLayout
            android:layout_width="330dp"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="God Father"
                android:textSize="30dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Crime Drama"
                android:textSize="30dp"
                android:textStyle="bold" />
        </LinearLayout>

    </LinearLayout>

After changing the size of parent layout, which covers the textview.

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/Crime">

        </ImageView>

        <LinearLayout
            android:layout_width="330dp"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="God Father"
                android:textSize="30dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Crime Drama"
                android:textSize="30dp"
                android:textStyle="bold" />
        </LinearLayout>

Upvotes: 0

Christopher
Christopher

Reputation: 10259

Your LinearLayout has height-attribute fill_parent. Change to wrap_content.

Upvotes: 13

ata
ata

Reputation: 9011

Check the layout_height of internal LinearLayout from match_parent to wrap_content

Upvotes: 2

Anjali
Anjali

Reputation: 2535

your innerLayout height is match_parent because of which your last textview was not visible

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:padding="10dp"
        android:text="Scrie un cuvant" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"   <<---- Change it to wrap_Content from match_parent
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/cuvant"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="@string/cuvant_hint"
            android:inputType="text" />

        <Button
            android:id="@+id/cuvantbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cuvantbutton_text" />
    </LinearLayout>


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:padding="10dp"
        android:text="Sau random" />
</LinearLayout>

Upvotes: 1

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

You are actually telling LinearLayout to capture all available space, which is causing you last textview not showing. Instead use "wrap_content" which tells to capture space required to show the available content.

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:padding="10dp"
        android:text="Scrie un cuvant" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/cuvant"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="@string/cuvant_hint"
            android:inputType="text" />

        <Button
            android:id="@+id/cuvantbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cuvantbutton_text" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:padding="10dp"
        android:text="Sau random" />

</LinearLayout>

Upvotes: 3

Related Questions