N
N
Niemand2012-12-17 11:01:19
Android
Niemand, 2012-12-17 11:01:19

Absolute positioning in Android?

Hello Habr.
Although I tried to develop for android for some time, I did not understand one moment. Namely, how to set absolute coordinates, indents for elements so that they look the same in all resolutions.
Problem: there is a certain toolbar block at the very bottom of the application, which is always located at the bottom. There is a popup-type View that is located on top of all other windows (for objective reasons), so it cannot be located relative to the toolbar. It must have a certain indentation from the toolbar, i.e. the indent is taken from the bottom of the display and is the height of the toolbar + the indent from it.
The problem is that if you set the indent in dip, then it is actually different for different resolutions. Setting the padding in pixels is also not an ideal solution. How to act in such cases?
As an example: a toolbar is 60 pixels high in mdpi (let's say with an image in the background that has a fixed size), which equates to 60 dip (1x factor, according to this page: developer.android.com/guide/practices/screens_supp.. . ), then in hdpi the same 60dip should be 90 pixels, which is most often true, but in xhdpi everything looks completely different.
Please help me figure it out.
UPD.
At the moment, I tried to solve this issue like this:
I separately calculate the ratio of the device screen width to 320 (usually the mdpi device width, i.e. 1x) and multiply the padding in pixels by this factor. But I don't think this is the best solution.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question