Is it possible to support both orientations on some screen sizes, but not on others?

In my applications, I currently only support portrait orientation for some activities, because I assume that most phone users will use portrait orientation (and hold the device with one hand) most of the time.

However, on the new Honeycomb tablets, it seems that users will use landscape orientation much more often, so I would like to support both orientations for most of my actions.

I would prefer not to come back and add landscape layouts for smaller screen sizes (up to QVGA), so I wonder if there is a way to support the landscape only for an xlarge screen but not for others.

+3
source share
1 answer

You can combine the attributes of the orientation and size of the resource objects , for example:

res/layout/             -- default
res/layout-port/        -- portrait for any screen size
res/layout-xlarge/      -- any orientation on xlarge screens
res/layout-xlarge-land/ -- landscape on xlarge screens

Use the directory layout-portfor your portraits only for smaller screen sizes, and then add xlarge layouts to the directory layout-xlargeif you want to use the same layout file for portrait and landscape on xlarge or layout-xlarge-landand layout-xlarge-portif you need different layout files depending on orientation.

, , , , , , Resources.NotFoundException. , Activity.setRequestedOrientation():

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        setContentView(R.layout.titlescreen);
    } catch (Resources.NotFoundException e) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        return;
    }
    [...]
}

, , , setRequestedOrientation() .

+8

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


All Articles