I'm trying to determine the cutout position on a Samsung S22 Ultra (SM-S908U). The only Rect returned by WindowInsetsCompat.getDisplayCutout().getBoundingRects() seems to be incorrect when the device resolution is set to 2316 x 1080. Is this just a Samsung bug?
Cutout position for each resolution:
1544 x 720 : Left = 341, Right = 379
2316 x 1080 : Left = 692, Right = 748
3088 x 1440 : Left = 683, Right = 758
Shouldn't the values for the 1080 resolution be about half way between the other two?
Related
I am trying to place textView on specific position related to point on picture (name of pin, which must be editable), I'am facing problem when using different screen size, so I is there any way to make this work.
I tried on some of my phones :
-4.3', 720 x 1280 pixels (~342 ppi density)
-4.0', 480 x 800 pixels, (~233 ppi density)
-5.1' 1440 x 2560 pixels (~577 ppi density)
When I make it work for one device it doesn't work for other two
I would like to make it like this
Scale the position of the text field by the same factor you scale up the image by.
scaledX= x_on_disk*image_width_on_screen/image_width_on_disk
scaledY= y_on_disk*image_height_on_screen/image_height_on_disk
I have a major issue I am working on for days now. It is much understandable by looking at the requirement first. I will list down my requirement as simple as possible in point form below.
I have 5 android phones. 5 different brands, different screen sizes.
Imagine the screen sizes are 4inch, 4.5inch, 5inch, 5.1inch and 5.2inch
I have an android app and it has a drawing canvas.
Now using canvas.drawCircle(x / 2, y / 2, radius, paint) I am drawing a circle. Imagine the radius is 100 (100 pixels?)
I install this app in my smallest screen phone, 4inch. Then I use a ruler and measure the the circle diameter. Imagine the circle diameter is "exact" 3cm.
Now I install this in my other phones.
Unfortunately, in my 4.5 inch phone the circle diameter is 3.2cm. In 5 inch phone it is 3.3 cm. In 5.1 inch phone it is 2.8cm and so on.
However I want my circle diameter to be 3cm (exact 3cm) in every phone.
Above requirement is something I am trying for days now. I tried the following to make sure I get a circle with no size change across all screens.
Using ImageView - I tried using an ImageView and added a circle image. I have given the width, height fixed. I have tryied setting the values in px, dp, inches etc. I also tried scalling options available for ImageView. Also tried placing the same image in drawable-nodpi folder. Tried creating drawable folders for all sizes (ex: drawable-mdpi, drawable-hdpi). Non of this stopped the image from being scaled.
Using Canvas - As explained in the above, I tried using canvas and drawing the image. The drawing scales.
Finding pixels per inch.- Tried finding pixels per inch of each phone programatically thinking I can find a way to develop a logic from it to dynamically draw the images in same size. I used several links including - Calculate PPI of Android Device. Most of them talk about getting screen resolution only.
How can I fulfill my requirement of drawing same size circles? If it can be done by knowing PPI, how should I do it?
The Answer before has worked for me but as long as it didn't for you I will try explain something I think it will help.
I have a device that have a density of 1 (160 px per inch), and the Display metrics told me that i have 320 * 480 pixels, with simple calculation I should know my mobile width and height in inch like this : 320 /160 = 2 inch for width , 480/160 = 3 . for now everything was just fine until i got the ruler and measured it and the surprise was this : I have a 1.65 * 2.48 inch !!.
Then I noticed that there is something called physical pixels per inch of the screen this was the relief for me and you can get it like this :
getResources().getDisplayMetrics().xdpi; //for width physical dpi
getResources().getDisplayMetrics().ydpi; //for height physical dpi
And now I can calculate my Physical width and height of my device like this :
my physical dpi for both width and height is 193.5238 so...
320 / 193.5238 = 1.65 inch width
480 / 193.5238 = 2.48 inch height
And that was correct !!.
Now back to your problem lets get the 3cm in pixels for any Phone :
getting the width in cm :
width in cm = width in inch * 2.54 (because 1 inch equals 2.54 cm)
getting the amount of pixels in each cm :
width in pixels / width in cm = Pixels per cm for width (px/cm)
now you want a 3cm then the pixels according to it is:
3 * Number = 3cm Pixels
all of the above can be shortened like this :
float devicePixelsWidth = getResources().getDisplayMetrics().widthPixels;
float deviceActualDpi = getResources().getDisplayMetrics().xdpi ;
float deviceActualInchWidth = devicePixelsWidth / deviceActualDpi ;
float deviceActualCMWidth = deviceActualInchWidth * 2.54f ;
float PixelsForActual3CM = devicePixelsWidth / deviceActualCMWidth * 3;
In the end, all of the above has been tested and approved by me and has the same accuracy of the previous Answer method :)
maybe this is not answer, but might be helpful
float _100MmAsPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM,
100/*mm unit set*/, getResources().getDisplayMetrics());
above gives me 1661.5354 on Nexus 5x and 1889.7638 Nexus 5 (emulator). both have fullHD display, but 5 has 4.95 inch versus 5.2 inch in 5x.
it means 100 millimeters is 1662 pixels on 6 and 1890 on 5x
I develope an App. I position my view calulating the position using the screen size. For example view A, I position axis X 30% screen width and Y 30% screen height.
I test my app in a Samsung S4 (xxhdpi, 1080x1920, 5'').
I test my app in a Sony Xperia Z (xxhdpi, 1080x1920, 5'').
View A in Samsung 4: X= 324 (30% of 1080) Y = 576 (30% of 1920).
View A in Sony Xperia Z: X= 324 (30% of 1080) Y = 576 (30% of 1920)
In the Samsung S4 its OK, but in the sony xperia the view is not ok. Comparing with samsung, its more to the right and are the same device size!
i dont know why this happend and how to fix it.
Greets
I ever have this issue, so i never do the calculation axis X and Y again.
I'm using Margin to all of my android application, and it's going so well so far than you need to use the axis X and Y.
Use the
- marginBottom
- marginTop
- marginLeft
- marginRight
Hope it helps!
How I can calculate height of software buttons (like in galaxy nexus or razr motorola hd) ?
Personally, I suppose that DisplayMetrics.heightPixels attribute is height of all screen without software buttons height and with height of status bar.
Hence, software buttons height = specification height - DisplayMetrics.heightPixels.
Exemple for nexus 7:
75(soft button height) = 1280(spec height) - 1205(DisplayMetrics.heightPixels)
Im right ? please confirm.
My assumption is right.
to generalize question and prove it, here manual measurement what I have done on telephone and tablet from screenshots :
SOFTWARE BUTTONS HEIGHT
samsung galaxy nexus
portrait: 48 dp
1280 - 1184 == 96 px == 48dp xhdpi
landscape: 42 dp
1280 - 1196 == 84 px == 42dp xhdpi
( attention!: in landscape, this is not height but width of software button placed on right side of screen)
on nexus 7
portrait: 56dp
...
landscape: 48dp
...
i have display image in android tablet..
real size is 209x209 px, it's actualy big..
but when i display it in android tablet, it's become small..
how much standart width and height for image in android tablet?
The available width and height of Tab in market are following:
Product Display Size Display Resolution Aspect Ratio
Motorola XOOM 10.1" 1280 x 800 16:9
Samsung Galaxy Tab 7" 1024 x 600 16:9
Cruz T301 7" 800 x 600 4:3
Coby Kyros MID7005 7" 800 x 480 5:3
Dell Streak 5" 800 x 480 5:3
Archos 43 4.3" 854 x 480 16:9
So no standard width and height for images for tab in Android.
You can only think about that which size is suitable for those.
You can use 520*340 for 1280*800
500*320 for 1224*600
420*320 for 800*600
What are the most common screen resolutions: Android phones
320 x 480
480 x 800
480 x 854
540 x 960
1280 x 720
1920 x 1080
What are the most common screen resolutions?: Android tablets
1024 x 600
1280 x 800
1920 x 1080
2048 x 1536
2560 x 1440
2560 x 1600
found list of screen res via gravitylab