TextView is not displayed

Please review the following code

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Game" >

    <TextView
        android:id="@+id/numberOfQuestionsLeft"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/numberOfCorrectAnswers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/numberOfQuestionsLeft"
        android:layout_alignBottom="@+id/numberOfQuestionsLeft"
        android:layout_marginLeft="34dp"
        android:layout_toRightOf="@+id/numberOfQuestionsLeft"
        android:text="TextView" />

    <LinearLayout 
        android:id="@+id/linearOne"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#49494f"
        android:layout_below="@+id/numberOfCorrectAnswers"
        android:paddingTop="20dp"
        >

        <TextView
            android:id="@+id/hint"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginBottom="30dp"
            android:text="Medium Text"
            android:textColor="#ffffff" />

    </LinearLayout>

</RelativeLayout>

This gives the following

enter image description here

As you can see, the text view hintthat should appear inside the line layout is not displayed. Why is this? You are welcome,

+1
source share
2 answers

Remove the android:layout_marginBottom="30dp"hints from your text view:

    <LinearLayout
    android:id="@+id/linearOne"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#49494f"
    android:layout_below="@+id/numberOfCorrectAnswers"
    android:paddingTop="20dp" >

    <TextView
        android:id="@+id/hint"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Medium Text"
        android:textColor="#ffffff" />

</LinearLayout >

You don't really need this linear layout, just follow these steps:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            tools:context=".Game" >

<TextView
    android:id="@+id/numberOfQuestionsLeft"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="20dp"
    android:text="TextView" />

<TextView
    android:id="@+id/numberOfCorrectAnswers"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/numberOfQuestionsLeft"
    android:layout_alignBottom="@+id/numberOfQuestionsLeft"
    android:layout_marginLeft="34dp"
    android:layout_toRightOf="@+id/numberOfQuestionsLeft"
    android:text="TextView" />


<TextView
    android:id="@+id/hint"
    android:background="#49494f"
    android:paddingTop="20dp"
    android:layout_below="@+id/numberOfCorrectAnswers"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_marginBottom="30dp"
    android:text="Medium Text"
    android:textColor="#ffffff" />

</RelativeLayout >
+1
source

You need to do this:

 <LinearLayout 
        android:id="@+id/linearOne"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#49494f"
        android:layout_below="@+id/numberOfCorrectAnswers"
        android:paddingTop="20dp"
        >

        <TextView
            android:id="@+id/hint"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="30dp"
            android:text="MediumText"
            android:textColor="#ffffff" />

    </LinearLayout>
+1
source

Source: https://habr.com/ru/post/1620063/


All Articles