I created my application in only one layout. but now I need to support high resolution screens. I have a ListView getting images from JSON.
android:layout_width="fill_parent"
android:layout_height="174dp"
Images are shown good size on 4 inch device, but on tablet images are cropped from top and bottom. so i added
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ellidokuz.com"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true"
android:xlargeScreens="true"
/>
this code to manifest. then copied list_v.xml to drawable-xhdi and drawable-xxhdi.
and then I changed
android:layout_width="fill_parent"
android:layout_height="174dp"
to
android:layout_width="fill_parent"
android:layout_height="350dp"
but still my application running the xml file in the layout folder. How can I set it to run xml file in drawable-xxhdpi folder?
just simple copy and paste your xml into different Layout folders
You don't have to put your XML layout file into drawable folders!!
Instead just just put it in:
layout-small
layout-large
layout-xlarge
...
There is some convention to achieve this as per google developers blog recommended. If you want to achieve your layout should work for both phones and tablets then there is a way to do is, create different folders for layout like layout-small, layout-mdpi, layout-hdpi, put your xml file into all the folders, but you must have same drawables folders as well with different sizes of images.
Refer this : link
High-resolution screens exists in different screen sizes. That means you should create different layout folder like layout-sw720dp for 10-inch tablets. Then you should create a corresponding drawable folder like drawable-sw720dp-xhdpi were you can put your pictures in. I wrote a blog about this. It covers more than your question and should help getting you started.
http://objectofclasshuman.blogspot.de/2014/04/android-user-interface.html
Related
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" />
In my application,I have tow alternative layout files and two alternative drawable resource images. My res directory structure is as follows:
res/drawable-hdpi/image.png
res/drawable-mdpi/image.png
res/layout-large/main.xml
res/layout/main.xml
in manifest file
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:largeScreens="true"
android:anyDensity="false"/>
My app loads both the layout files res/layout-large/main.xml and res/layout/main.xml but, both the layouts load image from res/drawable-mdpi/image.png and does not load res/drawable-hdpi/image.png. Please help me in this respect I would be very thankful to you for this act of kindness. Thanks in advance.
I think what you are looking for is to use configuration qualifiers.
It seems you are really misunderstanding what these folders do.
Your android will select folder based on it's screen size or pixel-density of device on which u run it
If Your device has a medium Pixel density and a large screen. So it selects its resources from the res folders with those given qualifiers.
res/layout-large/my_layout.xml
and images from
res/drawable-mdpi/my_icon.png
You cannot tell your device to get images from the hdpi folder because it does not have a high pixel density.
So you could either create a folder called
res/drawable-large-mdpi/
specifically for your device.
Or just make sure the right images are in the right folders.
You can create drawable-large-mdpi folder to use the drawables for your layouts which are under layout-large folder.
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