Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the center coordinates of phone screen

Can someone give me an example of how to get the center coordinates of the current displayed screen? I would like my objects to always be relative to the center coordinates of the active view.

like image 246
1QuickQuestion Avatar asked Jun 08 '16 16:06

1QuickQuestion


2 Answers

You can try with DisplayMetrics to achieve your solution

int mWidth= this.getResources().getDisplayMetrics().widthPixels;
int mHeight= this.getResources().getDisplayMetrics().heightPixels;
like image 72
Devrath Avatar answered Oct 21 '22 01:10

Devrath


int cx =screenHeight = displaymetrics.heightPixels; int cy = screenWidth = displaymetrics.widthPixels; float finalRadius = (float) Math.sqrt(cx * cx + cy * cy);

float is the center if the object

like image 33
Waqar Khan Avatar answered Oct 20 '22 23:10

Waqar Khan