Why is the Linear Layout not visible in my AVD?

Viewed 50

I tried to understand why my LinearLayout is not appearing in the AVD but nothing is working.. Please view my snapshot for more details and let me know if i'm making any mistake. I deleted the part of the relative layout present in this program for a less messy question code to debug

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="233dp"
    android:background="@android:color/holo_blue_bright"
    android:orientation="horizontal"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="16dp"
    tools:layout_editor_absoluteY="1dp">

    <Button
        android:id="@+id/button_small"
        android:layout_width="98dp"
        android:layout_height="wrap_content"
        android:text="Small" />

    <Button
        android:id="@+id/button_big"
        android:layout_width="164dp"
        android:layout_height="match_parent"
        android:text="Big" />

</LinearLayout>

1

2 Answers

Add constraint to LinearLayout cause they are ignored
remove

 tools:ignore="MissingConstraints" 

To see the missing constraints, every View needs to be constrained at least with two constraints (one for the vertical axis, one for the horizontal axis).

add/replace this in your code:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="233dp"
        android:background="@android:color/holo_blue_bright"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="@+id/other_layout"
        tools:ignore="MissingConstraints">

        <Button
            android:id="@+id/button_small"
            android:layout_width="98dp"
            android:layout_height="wrap_content"
            android:text="Small" />

        <Button
            android:id="@+id/button_big"
            android:layout_width="164dp"
            android:layout_height="match_parent"
            android:text="Big" />

    </LinearLayout>

in your code u haven't give the constraints value so, whenever you tried to run your code in your emulator or device the layout wraps to 0,0.

Related