Android Layout for 720x720 BlackBerry screen - android

My BlackBerry Q5 can run Android applications and I'd like to optimize one of my existing apps for its screen. The resolution is 720x720, but the runtime also inserts a bar in the bottom of the screen, so usable resolution for Android app is 720x620 pixels, so I guess that's what the phone reports to Android app as the resolution.
Is there a way to make a layout that will apply only to 720x620px screens? The documentation for supporting multiple screen sizes says that there are w<N>dp and h<N>dp qualifiers, but they use scaled dp units and also means minimum available width in dp units, so they would not be useful in here.

I needed to solve your problem too, this is my solution.
The Q5 and Q10 screen density is xhdpi (scale factor of 2.0) so max screen size is 720x720px / 2.0 = 360x360dpi
Quoting from the documentation, Table 2, "Available height" row:
Specifies a minimum available screen height, in "dp" units at which
the resource should be used
[...]
When your application provides multiple resource directories with
different values for this configuration, the system uses the one
closest to (without exceeding) the device's current screen height.
[...]
Added in API level 13.
Based on these, for Androids with API>=13 (including Blackberrys) you can put your Blackberry specific layout in "layout-h240dp" folder and all the others in "layout-h361dp"
Blackberry height is greater than 240dp and less than 361dp, so it will use layouts in h240dp folder.
Notes:
- If you don't add the 361dp folder, the 240dp folder will be used for every device with height greater than 240dp.
- I choose 240dp because it is a common minimium dimension for today devices.
- 309dp should work too as it less than 310dp (minimum height of BB's screen with bars)
- For Androids with API<13 you have to put a default layout in the generic "layout" folder, because the previous "h*dp" folders are ignored. if default layout is missing, the app should crash.

I don't mean to turn this into a full-blown answer, but I need the extra space.
For your assets, if you'd like to target them specifically for Q5 or Q10 devices, place them in the drawable-square folder. This changed from drawable-small-square due to deprecation.
If you plan on deploying to OS 10.2.1+ devices and don't want that back-bar to show by default, you can add a small configuration file to your app so that the system knows not to show it.
For more information on that, take a look at my blog:
Android Developers: Eliminate the Back-Bar in Your 10.2.1. App

Related

Layout Issue on Small Screens

I'm working on a Android App. Layout working fine on every device except where device screen size 480x800 & less.
How can create separate layouts by only targeting that screen size or less?
I'm already tried layout-hdpi, layout-small-hdpi & layout-normal-hdpi since phone like Nexus S, Nexus One are in hdpi category. But when I create separate layouts like layout-hdpi those layouts are affecting phone with bigger screen like Pixel, Pixel2, Nexus 5 etc.
Thanks in Advance
Phones (as opposed to tablets) tend to come in about three size groups (as far as Android resources are concerned): those with smallest width of 320dp, those with 360dp, and those with 410dp. The resources framework gives you a way to target any device larger than a certain width, so the correct technique is to put layouts for small screens on the default folder, and layouts for larger screens in one of the qualified folders.
Since it sounds like your layouts currently work well for anything 360dp or larger, you can make two layout directories:
res/
layout/
layout-sw360dp/
Put the special layouts for the small screens inside res/layout/ and put the “normal” layouts in the other directory.
Its not easy but you can also specify layouts based on the smallest width and you you supply the numbers. You can get more detailed and separate layouts that way however in my experience you will still run into that problem from time to time. In my current project using this method I have specific folders for W360 and W400 to deal with smaller devices for one specific screen.
https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
What you are looking for, is a layout bucket with the smallest width qualifier.
A layout with a set smallest width will be active, unless the smaller of the both dimensions (width or height) is lower than a certain value you can choose.
So, when a device has a smallest width below some value X it will use the default layout, when the value is X or more it will use the defined smallest width layout.
To create such a layout file in Android Studio, you wanna right-click your layout directory, click on new -> Layout Resource File and select the Smallest Screen Width qualifier from the list of available qualifiers. Now you need to specify your smallest width, which in your case should be slightly above 480dp. Give it the same name as your current layout file. Place your code for devices with a smallest width above 480p here. Now change the code in your other layout file, without the smallest width qualifier, to support smaller screens.
For further reference take a look at the official Android Developer page.

5.2'' and 5.0'' screen support on android devices

I have been struggling with this problem about a week and can not figure out how to make it work. I have some views on a screen. And one values\dimens.xml(sw320dp-xxhdpi) resource file. Also I have nexus 5.2 1080*1920 420dpi and nexus 5.0 1080*1920 xxhdpi. The layout appears differently on both screens. How to make it display the same on each device?
What resource file should I add (if it is any)?
How to add for example values\dimens.xml(1080*1920 420dpi)?
I think your layout is simply built as poorly scaling. Unless you have some very specific use case, you need to make sure your layout fills the area it is provided with regardless.
As for the resource folder, if you want to make sure the same layout file is used on large screens, it is enough to put it in the folder layout-sw360dp. If you have xxhdpi devices with the resolution 1080x1920, Android will select the same file for both since the smallest side will be exactly 1080 / 3 = 360 density-independent pixels.
How to make it display the same on each device?
In general it's impossible for all Android devices. I think best solution - using VectorDrawable or SVG format and scale vectors for each device.

Android studio layout size folders

I'm trying to create a different layout for 1080dp and others using
"layout-sw1080dp" folder but it seems android studio completely ignores it and loads from the default layout folder.
I've tried another way - setting different dimensions using values-sw1080dp and still nothing!
What is the correct way to write different layouts for different screen sizes?
DP is not the same as PIXEL!!!
You think it's ignoring because devices with 1080dp do not exist (yet?).
values-sw720dp: that's for Nexus 9 and 10 inch tablets
values-sw600dp: that's for 7 to 8 inch tablets
values-sw360dp: that's for small phones
I suggest you installing this app https://play.google.com/store/apps/details?id=nl.qbus.sizemeup&hl=en on your devices, it shows the size of each devive in pixels and in DP.
Also, read more about it here http://developer.android.com/guide/practices/screens_support.html
By default, Android Studio (version > 0.8) groups resources with the same name into one folder, with their distinguishing qualifiers in a muted grey. Be sure you're also using the correct qualifiers.
The modifier you're using sw<N>dp (smallest width) represents resources for the shortest of the screen's available height and width.
Are you sure your shortest screen's dimension are not less than 1080dp?
Read more about resource folder modifiers here.

In Eclipse activity layout view, the minimum available width specified by h<N>dp auto-chooses to wrong layout folder. A bug?

I am using eclipse with the ADT.
For the activity I am using portrait view only and thus want to use the h<N>dp xml qualifier to specify a minimum available height for the layout.
When I name my folder layout-h641dp and choose the Galaxy Nexus (640 x 360 dp) device from the drop-down then Eclipse auto-chooses the lower layout-h450dp as expected.
When I rename the folder to layout-h640dp then I can view the layout with the Galaxy Nexus, but it shouldn't since the available height is only 519dp plus 48dp (for the action bar) = 567dp (see the image) and google states at Supporting multiple screens that
Note: The sizes that you specify using these qualifiers are not the actual screen sizes. Rather, the sizes are for the width or height in dp units that are available to your activity's window.
and
Also beware that the Action Bar is considered a part of your application's window space, although your layout does not declare it, so it reduces the space available for your layout and you must account for it in your design.
I am thus not allowed by Eclipse to design on the correct layout that will actually be chosen by the physical device.
When actually testing on a Samsung Galaxy S3 (also 640 x 360 dp) using layout-h616dp the Android system uses the lower layout-h450dp layout, which is correct according to the Google docs, and when I then rename the layout-h616dp to layout-h615dp the Android system chooses layout-h615dp for rendering which is as expected, since the available space is about 640dp (total) minus 25dp (for the status bar) = 615dp.
My question: Is this a bug in Eclipse and if so, is there a workaround so that it is possible to design properly on the correct layout?
EDIT: To clarify, in a nutshell, Eclipse uses the total screen dp whereas when actually running the app the Android system uses only the available 'dp' (as it should).

Android font size in pt

I'm working on a Android project where I need to build my layouts based on a JSON layout file. This same file is also being used on an iOS app. So there is 1 file which will render the same layout on the Android as well as on the iOS.
The JSON layout file defines its font sizes based on the default iOS font unit.
From the Android docs:
Points - 1/72 of an inch based on the physical size of the screen.
And as far as I can find, iOS font sizes are also defined as 1/72 of an inch.
So based on this info, I'd say the following should be enough:
view.setTextSize(TypedValue.COMPLEX_UNIT_PT, fontSizeInIosUnit)
This however results in the text being too large. And it also seems to differ per device (which is weird since points should always appear in the same physical size).
If you want fonts to resize properly according to screen size you should use dp/dip instead.
So try this instead:
view.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSizeInIosUnit);
Now this might not be exacly the same but in my experience this gives the best results. If it doesn't have the proper size then figure out what size you need on Android as the base size and then go with that instead.

Categories

Resources