I am trying to place textView on specific position related to point on picture (name of pin, which must be editable), I'am facing problem when using different screen size, so I is there any way to make this work.
I tried on some of my phones :
-4.3', 720 x 1280 pixels (~342 ppi density)
-4.0', 480 x 800 pixels, (~233 ppi density)
-5.1' 1440 x 2560 pixels (~577 ppi density)
When I make it work for one device it doesn't work for other two
I would like to make it like this
Scale the position of the text field by the same factor you scale up the image by.
scaledX= x_on_disk*image_width_on_screen/image_width_on_disk
scaledY= y_on_disk*image_height_on_screen/image_height_on_disk
Related
I have investigated and read all the official Android documentation according to the topic of supporting different screen sizes to create different images sizes to support different screen densities. I have not found how to determine the accurate px size of an image of the baseline mdpi density.
I have found this old post of the forum which describes exactly my doubt:
How do you decide the pixel dimensions of your baseline drawable for Android?
That posts has an answer that is interesting but not really clear:
https://stackoverflow.com/a/8073233
In short words this answer says the following:
If you have a (50 x 40)dp image item (like a Button or ImageView), for the mdpi density you shouldn't create the exact pixels (50 x 40)px but you should create a larger image to be divisible by 5 and 4 (as the W:H ratio is 5:4), so for example for a (50 x 40)dp, you should create for mdpi density a (60 x 48 px) so that when it is multiplied by 0.75 for ldpi purposes give exect values (45 x 36 px).
Okay, so now my question is, how could I know how much "larger" should I make the image dimensions in px for the mdpi density (base density) if I have an image item of (X x Y) dp ? Should I make it 10px larger as the case?(Surely not) Or should I make it larger until the other densities in px give exact values? I would like to see a clear explanation of how to get that larger px dimensions of the mdpi density if I have an image item whose width and height is X and Y dp.
Is it possible to make a layout for this nexus 4 resolution . my app give problem with custom views.
i have
layout-hdpi
layout-xhdpi
layout-xxhdpi
i know xhdpi includes 768 x 1280 and 720 x 1280 .
dpi only partially depends on resolution. It is a measure of how tightly the pixels are packed on the screen. Thus, it is a function of both resolution, as well as the physical size of the screen.
Saying 768 x 1280 px = xhdpi may be correct for some devices, but incorrect for others. For example, what if you have a 10 inch screen that has that resolution? That would most likely be ldpi.
In order to support multiple screens, please follow this guide: http://developer.android.com/guide/practices/screens_support.html
You may want to use dp's instead of pixels in your layouts for setting widths and heights. You can then customize layouts based on the current width of the device by using layout directories such as layout-sw320dp ("smallest width 320 dp").
Dear Android Developers,
as far as I know, Android has 4 different types of screen resolution :
LDPI << ignore this, because I won't build my app in this resolution
MDPI : 320 x 480
HDPI : 480 x 720
XHDPI : 640 x 960
now, Google Nexus 4 has screen resolution : 768 x 1280, which I assume this categorised as XHDPI model. *please correct me if I'm wrong.
now take a look at my picture...
so, if I put XHDPI size (red area) on top of Nexus 4 screen (grey area) you'll see what I see.
now, if I have 4 white boxes horizontally and 6 white boxes vertically on red area (PSD design). what it looks like on Nexus 4 screen resolution?
can we programatically add more boxes (blue boxes) to fill the empty space? or Android will automatically stretch that red area until covers all grey area? which means all of white boxes will be stretched too...
that's all I need to know... thanks.
You should watch Roman Nurik's Design Bytes: Density-Independent Pixels video.
First, stop thinking in pixels. Think of devices using density-independent pixels. The buckets that Android uses (ldpi, mdpi, etc.) are not measured in pixels; they are measured in dots-per-inch (DPI).
Those buckets are actually:
LDPI: 120 DPI
MDPI: 160 DPI
HDPI: 240 DPI
XHDPI: 320 DPI
The Nexus 4 has a DPI of precisely 320.
Screen size and Screen DPI are different things. Check https://developer.android.com/guide/practices/screens_support.html
Screen resolution 1280 * 720 / xhdpi (Example: Sony Lt26i / Galaxy Nexus)
Which size of png/jpg for background(fill the whole screen without distortion) I shall use for the device (res/drawable-xhdpi), 1280px * 720px or 2560px * 1440px?
In this case, I always use 2560px * 1440px till I find some APPs use 1280px * 720px........
I believe double pixels shall be used on xhdpi screen.
Thanks a lot! ^_^
The exact size is: 1280x720 pixel.
When you hear about double pixels you are actually speaking about DIP, Density Independent Pixel.
A device which has a screen size of 1280x720 pixels, and has a XHDPI screen, will result in a 640x360 dp.
Android will take care of scaling and adapting the size for you, if needed.
Maybe it is a good idea to spend half an hour to read this:
http://developer.android.com/guide/topics/resources/providing-resources.html
I am developing for a Galaxy nexus 720P Phone. I have developed a background image to be exact 720P. But the image is been stretched. What should be the height and width of the image to not have it stretched on the phone ?
It depends on the Layout properties. If the imageview height is larger than the image you pass to the imageview, then the image will be streched. Set the imageview layout property layout_height="wrap_content" to not strech the image otherwise resize your image according to your phone height.
If you are developing specifically for the Galaxy nexus 720p, then your image should have the following dimensions: 1280 x 720
But you can't expect it to be properly displayed on all devices...
Take a look at this:
http://developer.android.com/guide/practices/screens_support.html
Try look about the draw9patch, it's a tool from Google for resize images :D
basically 3 densities are available
120 dpi (1 dp = 0.75 px)
160 dpi (1 dp = 1 px)
240 dpi (1 dp = 1.5 px)
px - pixel
dp - dots per inch
Check the dpi of your target device and create images according to the area you want to cover.
Eg: if the device is medium density(160) and you want to cover 720 dp create 720 px image
if device is high density(240) and you want to cover 720 dp 1080 px.
This will help you while creating images for devices with other configurations.