Android: position of buttons in screens with different resolutions - android

My Android application consists of several UI screens that contain a background resource and buttons that are placed on top of it.
The position of the buttons on top of the background is determined in the xml file of the layout.
In screens with different resolutions the background is resized to fit the screen.
This creates a problem that the buttons are not placed in the right place on top the background.
For example:
Using an emulator I checked it on a variety of normal size screens.
The background I used is compatible to a 480x800 resolution with density 240. But when I run it on an emulator with resolution of 640X960 and density of 320 the background is resized and the buttons are not placed in the right place.
The same thing happens on an emulator with resolution of 320X480 and density of 160.

Consider not sizing the picture to the total size but setting it to a defined size. So you will have somehow a black frame around your picture but no problem with different screensizes.

Related

image size advice

In researching android image sizes for different sized screens/densities etc., I've found an absolute tonne of things, a lot of which may be deprecated, and a lot of which may not be relevant to my situation, so I thought I'd ask for general advice.
My basic question is how big should I make my background image in pixels, or inches or centimetres? Probably pixels would be best.
My app is in locked in landscape mode, I don't need to worry about orientation.
I'm using a vector image, so I don't need to worry about scaling and quality issues
So, I want my background image to fit onto a ten inch tablet, so that it fills the whole screen with no scrolling.
On phones, I want the height(which would be the width in portrait mode) to match the height of the screen, and my image will be in a horizontal scroll view, so scrolls left and right in landscape mode.
So, do I need to do the whole creating different image resources for different dpi's thing, or will one do? What size should I make it?
I will also be lining up textviews with specific parts of the image, so presumably I'll need different layouts, as the lining up of textviews relative to the image will probably vary from screen size to screen size, resolution to resolution,bigger textviews for bigger screens etc. How do I implement this?
Thanks
Vector images should be used for icons only. In your case i'd just use a drawable & make sure you have different images for the different densities. Then create different layouts for phone and tablet. You should use a scrollview on the layout for the phone
The google pixel is a good representation of an android phone: It has a 1080 x 1920 resolution at 441 dpi. Then from the the android developer docs:
xxhdpi ~ 480dpi
you can scale the 1080 x 1920 down by the (3:4:6:8:12) ratios. if you image
has a different aspect ratio make sure that that the width or the height matches with 1080 x 1920 depending on the orientation of the device

Droid 9-patch Splash is black on some devices

I'm using a 9-patch to place a logo on the splash screen. This works on most test devices, as well as on simulators, but on one particular device – an SM-T230 – it shows up like this:
Image of splash screen where all space under the logo is turned black (Logo is deliberately blurred)
I created the 9-patch for all DPIs (LDPI, HDPI, ...).
It does appear to be scaling it; its size (in raw pixels) is about halfway between the size of the MDPI and HDPI images.
Any thoughts?
I believe I solved this by adding an extra pixel margin around the content of the image.

Handle Ui for all screen sizes

If i have specific layout which contains 2 ui components Application logo image and edit text, and i want to handle this layout for all screen sizes beginning from 2 inches to 10 inches.
I have taken a decision to stretch the layout components for high sizes and shrink it for small sizes, but i have some issues
1- How to test this layout to assure if it fits on all screen sizes, do i have to create at least one emulator for every group of inches ?
2- how I stretch the image view, shall i create dimensions for it for every group of inches?
3 - Application logo when i stretch it for higher screen sizes (7 and 10 inches) it get distorted and pixelated , what i have to do with this image, do i have to export app logo for every group of inches ?
Same application Logo should not be used for all resolutions. We need to place images with respective resolution in respective folders like
Lower resolution images in drawable-ldpi
Higher resolution images in drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi. Android OS takes care of selecting the image from respective folder based on the device screen resolution.
In order to test you can use an easier way i.e., in the Graphical Layout at the top there is a drop down with the last option as "Preview All Screens" where you can have a glance how is your design in all resolutions

Same pixel size but different screen size and resolution

I've an android project with layouts and resources for screen size large and mdpi (resources are in folders "layout", "drawable", and "drawable-mdpi").
The layout is mostly relative but some margins are given as absolute dp values.
The screens look perfectly on a device with above specifications (large/mdpi: aka device 1) and a pixel resolution of 480x800. Now, I have another device which has the same pixel resolution of 480x800 but since the screen is smaller, it has screen size normal and hdpi (aka device 2). The screens on device 2 look really messy (elements overlap etc.)
Since the pixel resolution is identical on both devices, it should be possible to create perfectly fitting screens for device 2 as well with little effort.
If I don't care about elements physically appearing smaller on device 2, what would be the approach to just physically "scale" my layouts (to fit on device 2)?
Just copying the drawable-mdpi to drawable-hdpi helps a little bit, but there are still problems. Are the absolute dp margins in the layout the problem? Should they be replaced by pixel dependent ones and everything is OK?
In general, what are best practices when I want to use a design that was originally created for a specific pixel resolution on devices with different pixel resolutions and I don't care much about elements appearing smaller or bigger?
In my case I basically just want to "scale" the original design and I don't care much about the vertical size (because the main view is scrollable anyway).

Screen sizes and precise element placement on Android

I have a problem with supporting different screen sizes. My application has different drawables for mdpi (320x480), hdpi (480x800) or ldpi (240x432). I also have different layout for small, normal-notlong, normal-long. Every size scaling or placement features are done in dp. However my problem is that I need to precisely place an element on the screen so it will perfectly fit to the background. One example here is an image that I download and show inside a frame that is part of the background. Or I also draw a circle (using drawArc) on the top of an imageview object and need to place it precisely to fit a 'black hole' that is on that image. Because the position is dependent on the background I place the elements with parent margins. As I wrote I am using dp for that. However If I fit my setting for a 320x480 3" screen and then change to 3.1" the elements are slightly misplaced and don't fit the background. The same if I have 480x800 3.5" device but change to 3.6" - the elements are misplaced slightly but that is enaught to look poorly in the design. What can I do about it? I am sure there has to be a way to achieve this on any screen size - i.e. games must use some kind of that mechanism and they work on any screen size. Can any one help?

Categories

Resources