Text image is not displayed
I have a linearlayout and a textview inside another linearlayout. A linearlayout is displayed from the inside, but the problem is that the last text is missing. 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>
Look at here,
+3
source to share
4 answers
In fact, you communicate LinearLayout
to capture all the available space, which does not result in the latter being shown textview
. Instead, use " wrap_content
", which says to grab the space needed to display 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>
+2
source to share
your innerLayout height matches match_parent which caused your last text to be invisible
<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>
+1
source to share