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!
Related
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 am using Translate animation for moving a view to down. I have set the android:toYDelta="65%p"
And i run the application on 2 devices(oneplus 2 and Nexus 5x) which are having same resolution. 1080x1920. But when the animation has done the layout animated differently.
Example: i have textview at the top of the layout, when i animate the layout it goes more down than the the Nexus 5x on OP2, even the screen size is same.
Thank you
Both have same resolution but they have different dimensions OnePlus 2 has (5.98 x 2.95 x 0.39 in) while Nexus 5x has (5.79 x 2.86 x 0.31 in) thats why you are feeling difference
I'm trying to support multiple screen sizes but I'm obviously missing something
I'm testing between a Samsung Galaxy Tab Pro (10.1 Tablet) and Samsung Note 3 (phone/fab)
DisplayMetrics WidthPixels HeightPixels Density DensityDPI
Tab Pro reports 2560 1600 2.0 320
Note 3 reports 1920 1080 3.0 480
I have all the layouts in /res/layouts and They all start with
RelativeLayout match_parent for layout_width and layout_height
My AndroidManifest.xml has
Ideally I would like to support screen resolutions of 1024 x 768 and larger
Which both the Note 3 (at 1920x1080) and Tab Pro (at 2560x1600) are
On the Tab Pro everything lays out the way I would like
On the Note 3 you are only seeing the upper left corner of the screen
It is almost as if the Tablet Layout has been cut in quarters
Y X
X X
And the Note 3 shows the Y only while the Tab Pro shows it all
Please help ? ?
Thanks in advance
Now I'm making wallpaper image for android tablet devices like Motorola Xoom or Galaxy Tab.
In android phones, typically wallpaper image size is 2 * screenWidth x screenHeight, but in Motorola Xoom it doesn't seem right because it automatically centered and scaled in weird way.
Is there anyone who knows about the exact image size for these devices or mechanism of wallpaper manager?
Thanks
If you have a Super TFT screen like the newer HTC phones, your phone has good (not great) black levels, sharp lines, and fairly good colors. Something with some black will be good, but don’t overdo is as you might notice some bluish tones when the brightness is cranked up. You can however do more intricate images thanks to the high sharpness of the screen. For regular LCDs, just avoid a lot of black and it should look fine.
Ideally,
the Height of the wallpaper should match with the height of the device (or some multiple)
the width can be anything more than the width of the device (keeping the aspect ratio and point 1 in mind)
The android launcher will automatically center the image and then divide the image across all its home screens, let us illustrate this with an example:
Say if there are 3 homescreens, the screen will focus at the center right away and if you flick towards the left or the right, it will scroll to that screen. In other words it the homescreen wallpaper will move 2 times.
(Taking that logic forward, if we have 5 screens, we will be able to move 4 times, if there are n screens, one is able to move n-1 times!)
This is how the formula works:
device_screenwidth + (number_of_homescreens - 1) x distance_moved =
image_width
Say we have an image with height = 800 pixels and width 1280 pixels, applying the formula
=> 1280 + (3-1) x distance_moved = 2000
=> distance_moved = (2000-1280)/2 = 720/2 = 360
in other words, the central 1280 pixels of the walpaper are displayed first, but every time you flick left or right the walpaper shifts by 360 pixels at a time.
This is how the wallpaper is displayed over the 3 screens:
screen 1: 0 to 1280 pixels
screen 2: 360 to 1640 pixels (1280 + 360) (This is the default home screen)
screen 3: 720 to 2000 pixels (1640 + 360)
That is how an image/wallpaper with a width of 2000 pixels and a height which is the same as that of the device (800) is mapped across 3 home screens on a device with a resolution of 800x1280 pixels
I'm working on the Android port of an app called RoadMap. Works on my smartphone and on two tablets I tried.
A user reports that on his tablet, RoadMap doesn't use up the full screen.
Turns out he changed the DPI with "DPIChanger" from 160 to 240. His physical tablet is a Kindle Fire, but with CM7 software. This device has 1024x600 pixels, like one of my own.
A debugging line on my own tablet shows (as it should) :
E/RoadMap ( 9574): Display dpi 160 (x 159.5681 y 160.42105) pixels x
1024 y 600
but on the user's tablet it says
01-29 12:51:18.968 5753 5753 E RoadMap : Display dpi 240 (x
164.61772 y 165.65218) pixels x 480 y 320
Is there a way for me to figure out screen size and add that to my app, or is the effect of DPIChanger just plain wrong and I shouldn't deal with such situations ?