My app doesn't detect layout-land folder with horizontal orientation screen

21 views Asked by At

I have created a layout-land folder where I have saved the designs of my specific layouts for the landscape version.... The problem is that when I install the application on my phone, when I rotate the screen, it continues to show me the same layouts as for the portrait version, as if it did not recognize the designs in the layout-land folder....

I would also like to say that I have verified that my phone does detect changes in screen orientation, when the screen is vertical the app shows a toast that says "Portrait" while when it is horizontal it shows a "Landscape" toast, which means my phone detects the orientation changes but nevertheless in landscape it does not apply the designs from my layout-land folder, and that is what has me puzzled... do you know if there is something that I am missing? Maybe some line of code in the activity tag of my Manifest.xml? Or what could I be missing...?

I want to get a responsive design of my app for screen orientation changes.

1

There are 1 answers

1
Pico On

My onCreate method in MainActivity is:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
}

So I understand that when starting the activity it will always call the layout corresponding to the layout folder, instead of showing the one from the layout-land folder. The issue is that I get an error when I try to put the following line:

setContentView(R.layout-land.activity_main).

Or by setting R.layout.activity_main would it be possible to also execute the layout of the layout-land folder, or that of other folders?

And also comment that I also have four other folders for the different screen sizes: layout-sw320dp, layout-sw480dp, layout-sw600dp. layout-sw720dp.