In the Android Studio design preview, my layout fits perfectly on screen.
Even when I played it though AVD, it fits well.
But when I connect my phone with Android studio and run it, it doesn't fit in my phone screen. It seems like centerCrop is on the whole screen. all layouts have the same problem.
I'm using a Samsung s8+. Preview setting is also Samsung s8+ which Android Studio provides.
At first, I thought that this problem is caused by 18.5:9 ratio of my phone. But in that case, the screen should be cut only at bottom and top. But it seems like centerCrop is enlarging based on the center?
The screenshot on the left is what I see on the preview and on the right is what I see on my physical phone:
Two Solutions:
Go for Linear layout if you don't bother layout hierarchy and coding style, as it fits for the most number of screens.
The design which you saw in the emulator will not be same in Actual mobile device in all cases. So try to debug your app in actual mobile device and design accordingly.
Make sure that your custom emulator has the same settings ( Height, Width, RAM ) as your phone.
Related
I'm working on a web application that uses Bootstrap 5.0 for the styling and I have a strange anomaly going on.
I have a collection of buttons (<a>...</a>) that are lined up in a horizontal pattern as shown in the attached image. As you can see, the desktop view looks great, but for some reason, looking at this on my mobile phone, the buttons are all crunched together indicating that the gap part of the class="d-grid gap-2 d-sm-flex" is being ignored by my mobile phone.
In my dev environment, I use the browser's dev tools (F12) to view it using Galaxy S5 in landscape mode which is the closest thing to my Galaxy A51 5G phone. My immediate suspicion is that perhaps it has to do with the fact that the gap-# in bootstrap translates to rem rather than pixels. I'm looking into that now. Until then please let me know if you have a more concrete answer.
Thanks a bunch.
Okay, I found an acceptable workaround, but I'm still interested if you know what the deal is with the gap-# not working on the mobile device. Here's what I did for now...
I removed all of the class="gap-#" and placed the following in the class of each button inside the foreach loop that places the buttons:
<button class="mb-2 mb-sm-0 me-0 me-sm-2" type="button" ... </button>.
This allows me to set the bottom margin of each button to have some space with the right side having no space while in mobile (portrait mode), but then have the bottom margins set to 0 and the right (end) margins set to have some space while in landscape mode and every size larger than the smallest size.
It seems a bit "hacky", but it works.
Please answer if you know a better way to get the gap-# to work in landscape mode of a small mobile device.
Thanks.
My android app looks different on the phone than android studio
look at screenshot
app in the phone screenshot
App in the Android studio screenshot
why is that? and how can I fix that?
Your preview shows what your layout would look like on a Pixel 3, which is quite a large phone. From what I saw on your screenshot looks like your device isn't quite as large so I'd recommend you to use ConstraintLayout for 2 reasons:
Consistency across different screen sizes - it's much more likely your layout will look the same on a large screen and a small one
Better performance, especially for your case since you'll be able to do everything with a single layout, without having to nest several layouts
For more information on ConstraintLayout, please check out this post I wrote on Medium
I am using the visual editor in Android Studio. In there, the text is really big, like how I want it to be. But when I build it on a physical device it is default size.
Thanks in advance!
simply create many layout that support pixels make all your layout handle your show way
read this to understand the idea
https://developer.android.com/training/multiscreen/screensizes
and do this in your code then check the devices
https://stackoverflow.com/a/8256573/6998825
there's also something else you may have not noticed yet
in android studio Preview Layout you can choose your the preview device as your actual device or same as it.
this way the preview design will be same as your device. but for other devices you should have above answers in mind.
I am newbie to convert android apps to bb10. I converted one app to bb10 compatibility. The app is compatible with both device and tablet in android.I successfully run it in bb10 simulator. But the app doesn't show the UI part completely. Why? I have one more doubt generally BB10 devices shape is rectangle but simulator shape is square. why?
BlackBerry Image
Android Image
That is because your UI needs more space than the resolution provides. If you would place your controls within a scrollable container, you would be able to scroll down to the missing parts of your UI.
If you choose that container to automatically show the scrollbar, this would only be seen on Q10 but not on Z10. Try to switch your simulator to Z10 resolution, then it will propably show all your UI elements.
The real solution would be really to define the UI in relation to the resolution.
To start with this, here is an excellent definition on how to cluster your layout resources for your Android app. Your problem will disappear, when defining an appropriate layout for the minimum height(!) of e.g. 600dp and one for 800dp. The one with 600dp will be used for the Q10 (because it has 720px physical height) and the other one for the Z10 (that has 1280px).
By the way: you should encounter the same problem on some Android device, since there are a few with nearly square display (I remember a "BlackBerry clone" by HTC?). But of cause, these devices are really rare...
reading about all these different resolutions and hardwares for Android I am a little unsure if the layout I created for an Samsung Galaxy will actually work the same way on all (most) Android devices.
I did not use anything fancy or complicated. However I had to use fixed width in several places to align text and buttons nicely. ALso there is some text with linebreaks that could look differntly if on narrower screens
How can I be sure that my layout will work on other devices? Or is this actually a no issue? Testing in the debugger is sooooo slow, that I actually never got it to work properly.
Thanks very much!
You can set up multiple emulators with different screen sizes, that simulate the possible targets.
In the emulator Ctrl-F11/12 (thanks #ccheneson) allows you to change the orientation, so that you can test that as well.
The emulator may be slow, but to see how the layouts look like it should be fast enough - you may still test the logic on a real device.
Also emulator speed seems to be highly dependent on the screen size.