Neoh
Neoh

Reputation: 16164

Support maximum screen aspect ratio without hard-coded ratio?

In principle, my app is agnostic of the aspect ratio of the screen (as it should be for an Android app). Now, the recommended practice is to manually add

<meta-data android:name="android.max_aspect" android:value="ratio_float" />

into the manifest because of the trend of smartphone screens with aspect ratio higher than the default supported ratio of 1.86. My question is, instead of setting a hard-coded ratio eg 2.1, is there a better way to tell the Android that I don't care what is the max aspect ratio?

If no, can I set an arbitrarily high value such as 3.1 or even 5.1? Is it safe to do so? I'm not talking about the exotic weird screen sizes but the mainstream future screens and the best practice to handle this in future. Thank you

Upvotes: 3

Views: 889

Answers (2)

Neoh
Neoh

Reputation: 16164

David's answer is correct if we want to support high aspect ratio screens on API < 24 (before Nougat). Going forward, however, the documentation says that android:resizeableActivity is true by default for API 24 and above. That means the app is automatically free-form in future (correct me if I am wrong). Considering that Galaxy S8 already ships with Nougat out of the box, I'd say there is no need to worry if your app is OK with free-form style.

EDIT: If your targetSdkVersion is < 24 then you should use David's solution because free-form will not automatically kick in for phones OS with Nougat (or higher) installed.

Upvotes: 0

David Medenjak
David Medenjak

Reputation: 34532

As you can see on Android Developers Blog they also hint on resizableActivity.

Note: if you don't set a value, and android:resizeableActivity is not true, then the maximum aspect ratio defaults to 1.86 (roughly 16:9) and your app will not take advantage of the extra screen space.

So you should add android:resizeableActivity="true" to your Activity or Application. The documentation also states

If this attribute is set to true, the activity can be launched in split-screen and freeform modes.

And it seems like freeform mode is what you care about.

Upvotes: 2

Related Questions