Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display.getSize vs Dispaly.getWidth

Tags:

android

I have a little issue here... I want to get the size of the display, which I can get either by calling the deprecated Display.getWidth / .getHeight or I can use Display.getSize...

But heres my problem... I don't want to use deprecated code, so that leaves me with Display.getSize... But that requires API 13 and I would like my min-API to be 8....

What should I do? Is there another option?

Point size = new Point();
display.getSize(size);

width = size.x;
height = size.y;

vs

width = display.getWidth();
height = display.getHeight();
like image 845
bwoogie Avatar asked Dec 01 '22 19:12

bwoogie


1 Answers

Use Display Metrics

DisplayMetrics display = this.getResources().getDisplayMetrics();

        int width = display.widthPixels;
        int height = display.heightPixels;
like image 68
Pragnani Avatar answered Dec 10 '22 11:12

Pragnani