Strange work of getDisplayMetrics() - android

I'm writing a small application and I ran into the following problem.
When measuring the screen height in pixels, FullHD screen gives out 1920px, and FullHD + screen (2160px) gives out 2030px. What could be the problem? And is there a way to solve it without crutches (ha-ha)?
FullHD:
getContext().getResources().getDisplayMetrics().heightPixels;
>> W/Height of screen: 1920
FullHD+:
getContext().getResources().getDisplayMetrics().heightPixels;
>> W/Height of screen: 2030
Perhaps the problem is that the FullHD screen I ran in the emulator, but FullHD + is native in Xiaomi Mi Mix 2s, but in any case, it does not solve the problem.
UPD: Yes, in emulator FullHD+ screen gives out all 2160px. I'm confused.

The size returned by this method (getContext().getResources().getDisplayMetrics().heightPixels)does not necessarily represent the actual raw size of the display.It could include the height of the statusbar,and sometimes not depending on the mobile system.
You can get the actual height of the activity window by the method getWindowsManager().getDefaultDisplay().getRealmetrics(metrics) which includs the statusbar always.

Related

Why ReactNative Dimensions component is reporting lowers resolutions?

I'm programming an application with React Native (v0.45.1) and using my S6 as a testing device. I'd set a background image which matches exactly my cellphone resolution size but its looking huge on screen, enough to only show me a small chunk of my background image.
Just for debugging purposes I'd added this lines in my render method to get my device dimensions:
let {height, width} = Dimensions.get('window');
console.warn(height, width);
and the output I got from those lines is: 360 x 640. How can that be possible? I'd taken a screenshot and shared to a coworker and the picture size is: 1440 x 2560, which is exactly my cellphone resolution.
A few days ago the same happened to me at work, for the record I was working with a tablet that time and not using my cellphone. Any ideas about what is happening or am I missing something? Thanks in advance.
The dimensions you get from Dimensions are in dp (for Android) and the picture size is in px (pixels).
Basically, you work in dp on your app and the actual pixels values will vary between devices depending on their pixel density. This means their pixels might be smaller/bigger, thus dp represents the real-world-uniform-pixel-size if you will.

Android Studio and a 4:3 resolution

My most resend project involves a Samsung Tab A 9.7" with 1024x768 pixels in a 4:3 format. This tablet is quite new and this format is unfortionatelly not supported by Android Studio so I've tried adding a new virtual device with these resolutions. I've set the scale option to: '1dp on device = 1px on screen'
The thing that seems wrong, is there is a difference between dp and px. If, for example, the width of a view is set to 1024px, it lines up nicely with the borders of the screen. But if I set it to 1024dp, it is much smaller... 1dp=1px means it is supposed to be the same, right?
When I launch it on the tab, all content gets wrong sizes etc (due to the problem above ofc).
Is there a way to propper add a 4:3 resolition so it can be used in the layout editor? I know there is a difference between px and dp but 1/1 is supposed to be the same?
Thanks a lot,
Jesse
After a long mixture between research and trail and error, finally 'found' the cause. When adding a virtual device in android studio for a custom resolution, it automatically focuses on portrait mode I think. Putting a view till the middle in portrait mode inside the editor -> In the middle in landscape on the tablet. Not sure if this is mend to be or an error of some kind.
Found out you can use the Nexus 9 layout, also 4:3 (2048 x 1538).
Thanks for the support Nanoc

Android emulator upside down

I am using Titanium to build an app. I created an android emulator using a standard device definition Nexus 4 (4.7", 768X1280: xhdpi, Android 4.1.2 - APU Level 16 , ARM (armebi-v7a) when I run it , the outside orientation appears correct but the screen itself is upside down. See image:
! [upside down emulator] (http://www.tiikoni.com/tis/view/?id=c0d737c)
I have deleted the emulator and re-created it a couple of times. I chose this one as it appears to have the highest screen density and the smallest screen physical size. Is there a way to fix this? when my app runs, it does appear correctly, but using the emulator is weird. Loke for opening the app drawer, you don't click on the icon where it is displayed, but you click where it should be.
Unchecking the "Use Host GPU" corrects the situation. I do not know why, but it does.
Try left Ctrl + F12. to rotate emulator.
also refer
The fix to this for me was very simple. I entered the resolution as height x width and it was upside down. So I entered width x height and it became OK.
Please check your XML and set proper background to the parent view.

Cheap Android 7' tablet (800x480): wrong aspect ratio, circles look like ellipsis

I need a lot of Android tablets for resale with my app. I bought some from internet (cheap chinese products) but all 7' 800x480 tablets shows circles as ellipsis (squares as rectangles), everything is stretched...
Some are Android 2.3.3, others are Android 4.0 but all of them show stretched UI.
Did someone have encountered the same problem?
After some flashing some new builds with changes in the sysconfig1.lhs, I've come to the conclusion that I don't believe there's a solution. The tests I did were on a Allwinner A10 tablet, specifically the M703 model running Android 4.0.4. Note that there are many devices with the same (or similar) hardware configuration but different names.
I dived into the sysconfig1.lhs that's included in the system image, which contains these lines:
lcd_x = 800
lcd_y = 480
And the corresponding touch screen values:
ctp_screen_max_x = 800
ctp_screen_max_y = 480
I measured the screen, which appears to be identical to Seraphim's measurement: 155×86mm. Working with that, I experimented with changing those values to either 864×480, or 800×444.
Unfortunately, neither option solved the issue.
864×480 simply clipped 64 pixels part of the display.
800×444 crashed SystemUI (as it no longer qualifies as sw480dp and therefore expected the device to be phone) and left a 36 pixel gap.
Perhaps the screen resolution needs to be set somewhere else, but I believe that it's the hardware that's somehow misconfigured.
There are many other lines in sysconfig1.lhs that are meaningless to me, such as:
lcd_dclk_freq = 33
lcd_if = 0
lcd_hbp = 46
lcd_ht = 1055
lcd_vbp = 23
lcd_vt = 1050
Perhaps there's some way of changing the pixel ratio, but I haven't experimented.
They are probably either:
not matching the screen physical size with the resolution aspect ratio. What is the physical size (width and height) of the screen?
having non-square physical pixels
If either of that is the case there is not much you can do unless you can do some serious hacking and change the resolution. You get what you pay for I'm afraid.

Android Emulator actual screen size

I want to optimize my app. I have a user with a Samsung Galaxy Note, 1280x800, 320dpi, Large Screen.
How do I set up the emulator's actual inch-screen size?
If I choose WXGA800 with 320dpi it makes a normal sized Version. How do I make it large?
Edit. Thanks for your answers, but that isn't the point. I know how to set up a an Emulator screen resolution and dpi. Actually I want an emulator to edit "layout-large-xhdpi" layouts but I get a "layout-normal-xhdpi" using 1280x800 with 320dpi in the AVD Manager. I simply want to change xlarge to large. Is there a way?
Edit2 Okay,found a workaround by temporarily removing the layout for normal sized xdhpi devices(Galaxy Nexus) and editing the Galaxy Note Layout as if it were some kind of "xhdpi" layout. But still it is strange to me, that it is impossible to edit directly a specific folder file like "layout-large-xhdpi". Found only in the Layout-Editor the possibility to add a screen size but unfortunately it won't make my layout.
Nevertheless I will have to make my layouts more flexible to have less problems ;-)
Thanks anyway
You can simply do that by opening your AVD Manager from Eclipse and when you are creating the emulator just check the Resolution radio button and input your desired screen size. Don't forget to change the density of the screen too. If you just want to emulate a Tablet you can simply make an emulator with Android API 2.3 or higher and it should have the desired dimensions..
#le chiffre : may I know why you want to increase the screen, as from my experience, if you use Eclipse then I think you can't increase the screen resolution of Emulator (if I'm wrong correct me please). The size of the emulator in landscape mode: width:800 and height:400 and I get this by this code
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
and if you want to scale your application, pictures,etc., you need to get the device width and height, so you don't need to worry about screen resolution. But I don't think emulator size can be increased.
Thx and hope this helps!
In Eclipse when you start the avd, you can set the option scale display to real size and set the display size and dpi.
Window -> Android sdk and avd Manager -> start -> you will get option here

Categories

Resources