I created an Android app and tested it on Nexus6 Emulator. Everything seems fine on Nexus6 Emulator but when I ran that app on real devices (Samsung S6 and S5) the layout was all messed up. How can I fix this?
Do I have to create separate layout for each device?
Does Android have something like 1 layout for all screens?
I dragged and dropped all images in drawable folder instead of using "add image asset". There is nothing in hdpi, mdpi folder. All images are in drawable folder. Is this the cause of my issues?
Please advise.
It is all about the design of your xml. When designing your pages, try to use 'match parent' and ensure that you are making a layout that fits across all screen resolution. Look into AFAIK...
https://developer.android.com/training/multiscreen/screensizes.html
https://developer.android.com/training/multiscreen/screendensities.html
https://developer.android.com/guide/practices/screens_support.html
How to define dimens.xml for every different screen size in android?
For example:
In your xml
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Related
I've created a android layout that looks fine on my Galaxy s2 (480×800) device. I want to support a layout for and Galaxy s3 (720x1280) so i created a AVD with those specs, then copied the res/layout directory and contents to two other directories: res/layout, res/layout-large and res/layout-xlarge. To test that the layouts were working positioned a test button at parent-center in res/layout, parent-left in res/layout-large and parent-right in res/layout-xlarge. If i run the application on my device (480×800) or in the AVD (720x1280) the test button is always at parent-center. Why isn't the test button positioned by the values specified in res/layout-large or res/layout-xlarge.
My manifest is as follows:
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" />
<supports-screens
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
I am targeting 2.3.3 and have also cleaned my build before testing
Im seriously going mad so any help would be appreciated.
I don't believe the Galaxy S3 is a "large" screen. Small/normal/large/xlarge refer to physical size, not pixels. You need a combination of screen density and screen size to target different devices. Read the Android guides and training for more details on this.
I have developed an application that is to be run on android Tablet as well. It is working on android phones perfectly. When I ran it on Tablet, it did not expand on whole screen. It just covered a area equal to a mobile device. I want that it also runs on Tablet and cover the whole screen as running on mobile device. Do I have to create two different designs for each type and at run time before using design, I would have to check it whether it is android phone or table?
Add below code in android manifest
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
Add the following block of code in your manifest file after the <uses-sdk>tag:
<supports-screens
android:xlargeScreens="true"
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
Note: Add the android:xlargeScreens="true" attribute if and only if your minSdkVersion is equal to or more than 9.
In addition to adding this block of code, follow this link. Also suggest you to go through the following links:
Supporting Multiple Screens
Supporting Different Screen Sizes
Supporting Different Densities
Hope this helps.
please try
<uses-sdk android:minSdkVersion="8" android:maxSdkVersion="11"/>
<supports-screens android:anyDensity="true" />
in Manifest.xml before tag.
I hope it may be help you.
Yes, ideally you'll design layouts targeted to tablets. You don't have to, but you can. See here for details. Your app is running in "screen compatibility mode". See here for info about that.
I think you used fixed width and height for any view or layout in your app, to support a fixed resolution of your mobile device.
If you use fill_parent, wrap_content and weight property, such things in your app, the app will fill entire screen of any android device. Once review your code.
Small example
Assume device has no rotation. Your device has resolution 320 X 240. you have to fill 3 buttons horizontally, you can put each button width=100 and remaining as margin/padding of layout. If you run same app on device with resolution 640 X 480, some space will come after 3 buttons. If you use width=fill_parent and layout_weight=1 for these 3 buttons and parent's layout_width=fill_parent, on any resolution these 3 buttons will fill the entire width of screen.
I hope it may help you.
Android Asus tablet is acessing images from android mdpi drawable and also lgoptimusp509 is accessing images from same mdpi folder.
Due to this I am facing alignment problems. How to fix this?
You should provide resources for multiple resolution and densities by following the guidelines at Supporting Multiple Screens.
There is also a tool from Google Android Asset Studio where you can upload your icons,menu icons,action bar icons and it will properly scale them for ldpi,mdpi,hdpi. You should also have a look at that.
You should provide resources for multiple resolution and densities.
so you have to put same images in hdpi,mdpi and ldpi drawable folder with diff resolutions.
and write this code in android manifest.xml
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
Devices access the images according to their density.so you should put same images in hdpi,mdpi and ldpi drawable folder with different resolution,so that those images will fit in respective devices.
I feel as if I'm missing something.
In my application, I decided to provide alternative drawable resources and alternative layout files. My structure is as follows:
res/drawable-hdpi/filename.png
res/drawable-mdpi/filename.png
res/drawable-ldpi/filename.png
res/layout-small/layout.xml
res/layout-large/layout.xml
res/layout/layout.xml
I created three different emulators: one with the default HVGA, one with QVGA, and one with WVGA800
It doesn't seem to pick up those alternative resources/layouts based on screen size/density, or maybe i just can't tell?
Is there some way, other than using a device for each specific size, to test this? Or am I just missing something important?
Another question, how well does Android scale drawables if no alternative resource exist?
A few points, in no particular order:
Layouts are related to screen size and thus to large, medium, small and drawables are related to density and thus to hdpi,mdpi,ldpi. It is obvious to some and not so easy to understand to others.
Read through this and create your emulator devices as specified in this page, double check to ensure you got them right.
Now start with just a simple layout and test it on the default device skin, then add layout-320x480, test, repeat for other sizes. If you are using layout-large/small etc, remember to add the correct lines to AndroidManifest.xml <supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizable="true"
android:anyDensity="true" />
One simple way to do this is to have a default layout.xml and drawables folder, and for different sizes have layout-320x480.xml etc folders and different densities we have drawables-hdpi etc folders. If you make sure to set android:anyDensity="false" /> in manifest file then the handset will get correct layouts and assets depending on its attributes.
If you set android:anyDensity="false" /> in manifest file the handset handles the sizing of drawables, typically taking assets from drawables folder and resizing it.
In 3.2 above version android developer have been released two new things for tablets
layout-sw600dp-land
layout-sw720-land
I have different layout files for
different screens size like
Folder Structure:
layout
layout-large
layout-small
For emulators like HVGA and QVGA there
is no problem, the respective
layout.xml file being refereed. But
the layout-large folder is ignored
when I run the emulator of
WVGA(480x854) , here it is referring
the "layout" folder of the
application. Please point me to the
right direction which is right way to
handle this situation.
I tried using
layout-large-hdpi layout-large-mdpi layout-large-ldpi
layout-normal-hdpi layout-normal-mdpi layout-normal-ldpi
And in the AndroidManifest.xml I
specified
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true" />
but no success
I think the Problem is that people always create a large screen by AVD Manager and it sets the default density to 240 which is not supported by /res/layout-large
If you want to want to test /res/layout-large/any_layout.xml then you should see the density of your virtual device it should be set to 160 not 240 or 120
Make sure the set up emulator's default size is "large" and not "xlarge".
For example if the emulator size is "xlarge", then the "layout-large" folder will be ignored and the default "layout" folder will be used, because it can't find a "layout-xlarge" folder.
This is easy to identify if your using Android Studio.
Have you checked if your API Level is already supporting this? I had this issue as well. In my case I used following line in the manifest, which set the TargetSDK to 4 (1.6), where the support of those different layouts started.
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
Links:
Screen Support