I'd like to set up a program that draws an inch square regardless of the terminal.
I thought about
①Get 1 dpi and get 1 inch square px
int dpi=getResources().getDisplayMetrics().densityDpi;
仮にIf it is 100px, it will be 10x10, so do をpx.
intippenn=(int)Math.sqrt(dpi);
正方Specify xpx on one side of the square
rect.set(0,0,ippenn,ippenn);
It was written in this way, but it didn't work at all and the square itself didn't appear.
If you rewrite the variable ippenn
to 100 and so on ( rect.set(0,0,100,100);
), the square was displayed, so I think drawing the square itself is correct.
How can I make it?
DPI is the number of pixels per inch in length.The DisplayMetrics specification also returns one of 120, 160, or 240, so you don't need to take a square root.
Because dpi values can be different in the x and y directions, you might want to use xdpi
and ydpi
in DisplayMetrics
.
http://developer.android.com/intl/ja/reference/android/util/DisplayMetrics.html
© 2024 OneMinuteCode. All rights reserved.