Setting up the Android emulator with a larger screen aspect ratio - android

In March 2017, an announcement was made that two Android devices — the Samsung Galaxy S8 and the LG G6 — were being introduced with new, longer, screen aspect ratios of 18:9 and 18.5:9.
According to the announcement, legacy apps with no android.max_aspect or android.resizeableActivity value in their manifest would take on a maximum aspect ratio of 1.86 (roughly 16:9) by default. The announcement shows an image of such an app running on one of the new device screens with its content "letterboxed" in the display with black bars shown along the top and bottom of the screen.
How can I set up the Android emulator to display one of the new, longer 18:9 screens? Manually setting the emulator screen resolution doesn’t show the letterboxed effect.

Try these steps:
In Android Studio, open AVD Manager
Create Virtual Device
New Hardware Profile
Set name: "18:9 aspect ratio screen"
Set resolution: 1080 x 2160
Finish
Select "18:9 aspect ratio screen"
Next
Select system image Nougat (API Level 25)
Next
AVD Name: "25 N.1 18x9 aspect ratio screen" [starting AVD names with the API level gets the list sorted by that]
Finish

This is not an answer per se, but I did find some helpful information in the docs.
First, read this note about android.max_aspect from the original announcement:
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.
Now see these docs:
You do not need to set a maximum aspect ratio if an activity's android:resizeableActivity attribute is set to true. If your app targets API level 24 or higher, this attribute defaults to true.
This means the "letter-boxing" issue will only happen if both of these conditions are true:
The device has a large aspect ratio (> 1.86:1 or 16:9), and,
The app targets API 23 or below
So I suspect the situation is not too bad - not many apps will be affected.

Related

Force all layouts to have a maximum area on very large screens

I have a pseudo-legacy Android app with hundreds of layouts that work nice up to 7-inch screens. However, I would like to run it on really large screens too (10 inches and up), but the system expands all the layouts to fill up the remaining space. I would really like to be able to define a maximum area for these large screens and simply have a black border that fills the remaining area.
What I want is apparently exactly as the behaviour on the screen compatibility mode that existed in really old Android devices:
On Android versions 1.6 to 3.1 the system runs your application in a
"postage stamp" window. It emulates a 320dp x 480dp screen with a
black border that fills the remaining area of the screen.
However, what the system does nowadays is:
On Android 3.2 and up the system draws the layout as it would on a
320dp x 480dp screen then scales it up to fill the screen.
I just don't want that scale up. Any ideas without having to edit every single layout for this? (and without having to provide a res/layout-large/ version for every single layout, evindently).
This requires a bit more logic and work but you might do:
Have your layouts contained in a parent layout/Custom View.
Parent layout will be default to match the sizing you need based on screen density or width/height as needed
Custom View will extend FrameLayout for instance and will look for a flag that will restrict the sizing to a center block on large screen devices or full screen on devices you wish to support.
Hope this helps.
====
Update:
Override the SetContentView Function and add the logic there - to have a container that bounds the layout in a center square if screen size is large or go directly to call super with the code as normal.
I have not actually used it. But There are few things you can try:
1. Declare a maximum aspect ratio
You can define android:resizeableActivity false for an entire app, or specific activities. The behavior is little different for Android 7.1 (API level 25) or lower, AND Android 8.0 (API level 26) or higher devices. For Android 8.0 (API level 26) and higher, you can define android:MaxAspectRatio in the Activity tag and for Android 7.1 and lower you can define android.max_aspect in the Application tag. By doing so, Your app will be letterboxed when it runs on a device with an aspect ratio greater than the one you specify.
2. Declare a maximum screen size
You can disable resizing beyond a certain width by specifying the largestWidthLimitDp attribute in the manifest tag. Then, instead of resizing your layout, Android enables screen compatibility mode, which draws your layout as it would on the largest size your app supports, and then scale up all the pixels to fill the screen.
You can read more about Screen Distributions
I hope this helps :)

Android layout qualifiers

I currently work on an application which has to support different screen sizes. I read through the documentation about this and decided to create different layout with the smallest width qualifier. The documentations notes:
smallestWidth - sw<N>dp The smallestWidth is a fixed screen size characteristic of the device; the device's smallestWidth does not change when the screen's orientation changes.
Available width - w<N>dp This configuration value will change when the orientation changes between landscape and portrait to match the current actual width.
I did so and everything works great but nevertheless I am a bit confused: Due to device metrics the Google Pixel should have a minimum width of 411 dp. In my application I created a layout with the sw480dp qualifier but when I select the Pixel device from the Android Studio layout editor it always opens the normal layout without qualifier.
I also tried to create my own hardware profile for the Galaxy S6 (360 dp) through the AVD manager but it faces the same problem. Have I missunderstood something here?
I also do not quite understand this image from the documentation. How do I have to read it? The small, medium, etc. qualifier are deprecated so why are they in there or is this only used for conversions?
In my application I created a layout with the sw480dp qualifier but when I select the Pixel device from the Android Studio layout editor it always opens the normal layout without qualifier.
411 is less than 480. Hence, -sw480dp is not a valid qualifier.
Have I missunderstood something here?
The NNN value in -swNNNdp is the lower bound, not the upper bound. Devices with a smallest width of NNNdp or larger would use -sw480dp.
How do I have to read it?
I have no idea what information that image is supposed to be conveying.

Android black bar below status bar. What is it?

Android 7.0
After installing my app and hockeyapp app I have weird black bar under status bar. What did it? How to fix it?
It sounds like you are reffering to the Samsung S8 device.
Inside the Application tag in your manifest, try adding the meta data for max aspect ratio.
<application ....
.... >
<meta-data android:name="android.max_aspect" android:value="5.0"/>
....
....
</application>
Most devices have rectangular screens whose width is fairly close to their height, ranging from the 4:3 ratio of a traditional television screen to the now-common 16:9 ratio. However, in some situations an app might run on a device with a more extreme aspect ratio.
An app can declare the maximum aspect ratio it is able to support. If the app runs on a device with a more extreme aspect ratio, the system automatically letterboxes the app, leaving portions of the screen unused so the app can run at its specified maximum aspect ratio.
The Samsung S8 has one of these "extreme" aspect ratios, so it must be specified that you support them. Why this is not by default, I don't know
You should be able to overcome this if you target API 24 and above. Otherwise, try setting the max aspect ratio to something greater than the recommended minimum of 2.1.
Note: You do not need to set a maximum aspect ratio if an activity's android:resizeableActivity attribute is set to true. If your app targets API level 24 or higher, this attribute defaults to true. For more information, see Configuring your app for multi-window mode
Android documentation about the issue can be found here

Cheap Android 7' tablet (800x480): wrong aspect ratio, circles look like ellipsis

I need a lot of Android tablets for resale with my app. I bought some from internet (cheap chinese products) but all 7' 800x480 tablets shows circles as ellipsis (squares as rectangles), everything is stretched...
Some are Android 2.3.3, others are Android 4.0 but all of them show stretched UI.
Did someone have encountered the same problem?
After some flashing some new builds with changes in the sysconfig1.lhs, I've come to the conclusion that I don't believe there's a solution. The tests I did were on a Allwinner A10 tablet, specifically the M703 model running Android 4.0.4. Note that there are many devices with the same (or similar) hardware configuration but different names.
I dived into the sysconfig1.lhs that's included in the system image, which contains these lines:
lcd_x = 800
lcd_y = 480
And the corresponding touch screen values:
ctp_screen_max_x = 800
ctp_screen_max_y = 480
I measured the screen, which appears to be identical to Seraphim's measurement: 155×86mm. Working with that, I experimented with changing those values to either 864×480, or 800×444.
Unfortunately, neither option solved the issue.
864×480 simply clipped 64 pixels part of the display.
800×444 crashed SystemUI (as it no longer qualifies as sw480dp and therefore expected the device to be phone) and left a 36 pixel gap.
Perhaps the screen resolution needs to be set somewhere else, but I believe that it's the hardware that's somehow misconfigured.
There are many other lines in sysconfig1.lhs that are meaningless to me, such as:
lcd_dclk_freq = 33
lcd_if = 0
lcd_hbp = 46
lcd_ht = 1055
lcd_vbp = 23
lcd_vt = 1050
Perhaps there's some way of changing the pixel ratio, but I haven't experimented.
They are probably either:
not matching the screen physical size with the resolution aspect ratio. What is the physical size (width and height) of the screen?
having non-square physical pixels
If either of that is the case there is not much you can do unless you can do some serious hacking and change the resolution. You get what you pay for I'm afraid.

Android wallpaper/background dimensions

Which are the default dimension of the Home wallpaper/background for the various Android screen configurations (small, normal and large screens with low, medium and high density)?
Are 9-patch PNG files supported for the wallpaper? Should I be using these instead?
I found a method in API level 5 that gives you the minimum size of the wallpaper, but I would like to support previous versions of Android as well.
Thanks!
A wallpaper is twice as wide as the device held in portrait mode. So 960x800 on a Nexus One, 960x854 on a Droid, 640x480 on a G1/Magic/Hero, etc.
This article on the Android Developers' site shows the range of screen resolutions for each density.
I believe the wallpapers have to match the screen resolution and are not stretched. You can see this if, for example, you create a new emulator with a high screen density like 480x854. The default home screen background is centred, with large black bands at the top and bottom.
The WallpaperManager API indicates that you must use a PNG- or JPEG-format image, even if you use the setResource() method — the resource must be a Bitmap and so not a nine-patch or other type of Drawable.
Don't guess, ask the WallpaperManager:
manager = WallpaperManager.getInstance(this);
width = manager.getDesiredMinimumWidth();
height = manager.getDesiredMinimumHeight();

Categories

Resources