F
F
Freijer2022-03-14 08:08:47
Java
Freijer, 2022-03-14 08:08:47

Determine coordinates of objects on screen, Android studio (java)?

Good afternoon. I need to determine the size of the display and, depending on its size, set the location of several buttons.
When you click on one of the buttons, you need to place a few more buttons so that the new buttons in no case intersect with other buttons and go beyond the screen.

I do not ask you to write code for me, but I will be grateful for the description and examples.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Savelyev, 2022-03-14
@AgentSmith

Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics ();
display.getMetrics(outMetrics);

float density  = getResources().getDisplayMetrics().density;
float dpHeight = outMetrics.heightPixels / density;
float dpWidth  = outMetrics.widthPixels / density;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question