Home > Mobile >  "The layout "layout" in layout-land has no declaration in the base `layout` folder (.
"The layout "layout" in layout-land has no declaration in the base `layout` folder (.

Time:09-07

I've set up a video showcase, that plays a specific video when the attached image button is pressed. However, I'm having some issues with portrait and landscape modes.

In an attempt to solve this, I followed several threads on here and created a "layout-land" folder with a layout.xml, then copy-pasted everything from the activity_main.xml file.

However, I still can't get the app to recognize and use the land layout when tilting the phone or tablet, and the only error I have is this:

"The layout "layout" in layout-land has no declaration in the base layout folder; this can lead to crashes when the resource is queried in a configuration that does not match this qualifier"*

So far I've tried: Ctrl C & Ctrl V on the XML text. gradle sync, invalidate cache, app pc restart and changing the XML file ID to match.

<?xml version="1.0" encoding="utf-8"?>
<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:id="@ id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<ImageButton
    android:id="@ id/imageButton1"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_marginEnd="520dp"
    android:onClick="Click1"
    android:src="@drawable/placeholder1"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:ignore="SpeakableTextPresentCheck"
    tools:srcCompat="@tools:sample/avatars" />

<ImageButton
    android:id="@ id/imageButton2"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_marginEnd="170dp"
    android:onClick="Click2"
    android:src="@drawable/placeholder2"
    app:layout_constraintBottom_toBottomOf="@ id/videoView1"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:ignore="SpeakableTextPresentCheck"
    tools:srcCompat="@tools:sample/avatars" />

<ImageButton
    android:id="@ id/imageButton3"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_marginStart="170dp"
    android:onClick="Click3"
    android:src="@drawable/placeholder3"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:ignore="SpeakableTextPresentCheck"
    tools:srcCompat="@tools:sample/avatars" />

<ImageButton
    android:id="@ id/imageButton4"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_marginStart="520dp"
    android:onClick="Click4"
    android:src="@drawable/placeholder4"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:ignore="SpeakableTextPresentCheck"
    tools:srcCompat="@tools:sample/avatars" />

<VideoView
    android:id="@ id/videoView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>

PS. How do I get proper colors in my code snippets? First time I'm using it.

CodePudding user response:

All credits to @Mike M's comment.

The landscape.xml file has to be named the same as the original activity_main.xml file for the tilt to work. Just ignore Android Studio's warnings and complaints when renaming.

  • Related