简体   繁体   中英

Android tools:screenOrientation equivalent

I have an Android app that is always run in landscape orientation. Works fine in that regard.

I'd really like it if Intellij/Android Studio editor ITSELF could be told that this is to be loaded in landscape (ie NOT try to load my activities in portrait mode -- I'm trying to spare myself that mouseclick in the editor, which I'm really beginning to resent).

Following the usual standard, the directive to get the Activity into landscape is something like android:screenOrientation='landscape' , so one would think the equivalent would be tools:screenOrientation='landscape' but that's not an option.

Is there one to get the editor to load an activity into landscape? If so, what?

Currently this is not supported by Android Studio.

A workaround could be to create the same layout resource in the layout folder with the same name but empty content (which will never be used), then place the real layout in the layout-land folder which Android Studio always opens in landscape by default.

Example: Let's say that you have a layout called activity_main.xml

Create an empty layout with this content (or any other view of your choice)

<?xml version="1.0" encoding="utf-8"?>
<ViewStub xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

and put it in the res/layout folder just as placeholder to not warn the compiler

Then create another activity_main.xml with the real landscape layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- your real layout -->

</androidx.constraintlayout.widget.ConstraintLayout>

and put it in the res/layout-land folder.

Now every time you want to open a layout, just open the layout-land one and it will automatically open in landscape in the layout editor

I don't think that is possible. Android Studio will always give you a portrait mode by default.

Left Ctrl + F11 is a shortcut to change the orientation in the emulator but I don't know if any such shortcut works for the XML layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM