I have a 1st Generation Nexus 7 that I am testing with. The app I'm working on only supports portrait. I'm trying to use the h1024dp numeric selector on the drawable directory to use specific images for devices like the Nexus 7. My directory is named:
drawable-h1024dp-hpdi
It is my understanding that any hpdi device that has a height of 1024 or more would use the drawable in the directory above.
I'm using hpdi as the second selector on that directory because my Nexus 7 is pulling its other drawables from the drawable-hdpi directory.
The screen size of my Nexus 7 is 1205 x 800 as detected by this code:
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point screenSize = new Point();
display.getSize(screenSize);
screenHeight = screenSize.y;
screenWidth = screenSize.x;
My app is NOT using the drawables in the drawable-h1024dp-hpdi directory as I expected it would.
What am I missing?
What am I missing?
1024dp would be a height of 1024 density-independent pixels. One density-independent pixel is 1/160th of an inch, so 1024 of them are 6.4 inches. Your Nexus 7 does not have a screen size that is 6.4 inches high -- it is about 5.9 inches. Hence, that resource set does not qualify.
Or, to look at it another way, the screen height is 1280px at ~213 dots per inch (-tvdpi), which works out to around 960dp.
Related
So, i read the docs on how to support multiple screensizes. i have no problem for screen qualifiers greater than sw320 . but when i tried my emulator on devices <=320 like nexus S, the images overlaps with each other.
Nexus S has a screen size of (480 x 800) and it's density is 240dpi
so calculating using the formula given in the docs:
px=dp*(dpi/160)
dp= px/(dpi/160)
dp= 480/(240/160)
dp= 320
so using the qualifier < sw320 > should have worked yes? but it's not working in my situation. I tried changing the bitmaps to drawable-hdpi too but the emulator didn't use that drawable
Did i do something wrong?
Although this question is not related to programming, it is related to app development.
Suppose I have an ImageView whose dimensions are 40dp*40dp. If I use the above formula to create an icon for a device with screen density 217 ppi, the size of the icon that fits the ImageView exactly is 55px*55px. If I use this icon in the view in consideration, the result is that the icon does not appear very sharp.
On the other hand, if I use a larger image of size, say 80px*80px, it appears sharp. So this larger image is larger than the exactly fitting one by a factor of 1.6.
What I would like to know is whether there is a certain value of the above factor that is most efficient and conventional. I would like to follow conventions while developing my apps.
Thanks for your time.
Your ImageView size is 40dp, thats equal to:
40 x 1.0 = 40 pixel on mdpi devices
40 x 1.5 = 60 pixel on hdpi devices
40 x 2.0 = 80 pixel on xhdpi devices
40 x 3.0 = 120 pixel on xxhdpi devices
40 x 4.0 = 160 pixel on xxxhdpi devices
Now your device is hdpi (217). for thats device you need a 60x60 pixel bitmap, and you have to put it in the drawable-hdpi directory.
Using drawable directory is like using drawable-mdpi directory. fro each resource in that directory android will scale it up/down before using it.
I have one problem with UI widget sizing, see 2 devices below as an example,
1.) Samsung Galaxy Tab 2 7"
- Pixels : 1024x600 (mdpi)
- DPI : 160
- Density : 1.0
2.) Samsung Nexus 10 2013
- Pixels : 2560x1600 (xhdpi)
- DPI : 320
- Density : 2.0
If I place a widget with 50dp, by using px = dp (DPI / 160), it would be 50px for Tab 7" and 100px for Nexus 10. But in term of percentage, 50px is equal to 4.88% of screen width on Tab 7" while 100px is 3.9% of screen width on Nexus 10.
But, I need this widget to appear with same width percentage. So, I came up with 2 options.
A. Calculate at run time by getting the physical pixels and apply percentage, then resize the widget.
B. Calculate size and place in < dimen > in different xml file (sw600dp and sw700dp for my case).
As of now, I'm using option A to calculate size and set at runtime. It works well but I'm afraid that the calculation could affect the performance. If I choose option B, I will need to calculate size for every widget in every screen (50dp for Tab 7" and 62.5dp for Nexus 10 will result as 4.8% on both). But, if I want to change this value later or some manufacturer introduce new device with difference DPI or pixels (imagine, 7" tablet with hdpi resolution, 1.5 density, 240 DPI), I will have to redo all the calculation and update or provide new xml again.
So, my question is, is there an option C which will not slow down the performance and not taking a lot of manual calculation into account in future?
P.S. Sorry, I forgot to mentioned that I also using weight approach with my static widgets already, but my question is about dynamic-generate widget. For example,
a gridlayout that showing 5 columns on Landscape Tablet
a scrollview to show 4 rows per page on Phone
an ImageView with 5% padding
an ImageView with an aspect ratio on every device.
dp are almost equal on all devices in size, not in screen %
If you need same screen % then just get display size & calculate desired % of it. Then dynamically apply to your widget
Today, I read the android tutorial about supporting multiple screen. I got some problems here. In the tutorial, it says we can use size and density-specific resource in this way:
res/layout-w600dp/main_activity.xml
I know that w600dp means the available width is 600dp. But is it for portal or landscape?
Here is real case:
I want to design a full width header image for my android app in portal mode. This app is targeted for Samsung Galaxy S4, which has 5.0 inches, 1080x1920 pixels with 441 dpi. That means my header image need to be 1080 pixels. As android tutorial mentioned, in android, px = dp * (dpi/160); In Samsung Galaxy S4 example, 1080px width is 391dp. So do I need to declare the layout in:
res/layout-w391dp/main_activity.xml
or
res/layout-w320dp/main_activity.xml
When I am using Photoshop to create my header image, do I need to set my image parameter as 1080 width, 40 height and 441dpi? After I get the image, do I need to put this image in:
res/drawable-xhdpi/
or
res/drawable-w600dp/
The available width value will change when the orientation changes between landscape and portrait to match the current actual width.
If you want provide different layouts/resources for landscape and portrait add the qualifier name -land or -port respectively. See more at Android documentation
If you want fill all the available width don't think about dpi. If device width is 1080px then you need an image with 1080px. However, if you want an image look the same at diferent devices with diferent density then calculate its dimensions by applying these factors:
ldpi = 0.75
mdpi = 1
hdpi = 1.5
xhdpi = 2
xxhdpi = 3
It is not possible here to do a full explanation on this subject, and my English is not enough for such.
I have received reports of my app not scaling properly on a specific device, the galaxy s 2 and I am trying to make a new layout for devices with similar resolutions. I have been reading this site: http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources and I have tried making folders called /layout-w480dp and /layout-sw480dp but the new layout never is picked up in the emulator that i have set with a width of 480 dp. What should the folder be called so that on a device with a width of 480 that layout is used instead of a scaled version of the default layout?
The correct layout-identifier to use for the s2 is:
layout-sw320
It's HDPI so the scaling factor is 1.5. The resolution is 480x800, so the calculation is (480 / 1.5), which equals 320.