This question already has answers here:
Application Skeleton to support multiple screens
(2 answers)
Closed 9 years ago.
How to Solve Screen Resolution Problem?
I want my application run on any android device, and its layout should not change,
I read android Blog of Supporting Multiple Screens,But do not get enough idea.
I have created different layout folder like layout-small,layout-normal,layout-large,layout-xlarge and created different XML files for all folder.
But when i run on Tablet it takes Default normal size XML file,I don't know why?
Please help me to solve it, Thanks in advance and Waiting for response
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
Add this to your manifest file of app.
Create the layout and drawable with following qualifiers
layout-sw600dp drawable-sw600dp
which means tablet screen with minimum of 600dp and higher can use this layout and drawable.
So for standard configuration qualifiers for screen size you can create following configuration:
1)layout-sw480dp drawable-sw480dp
2)layout-sw600dp drawable-sw600dp
3)layout-sw720dp drawable-sw720dp
check http://android-developers.blogspot.in/2011_07_01_archive.html
Following the guide will only help you to deal the problem for the most cases, but never all the scenarios. Check the following list which is the Google's AOSP homescreen source code. Even this cannot guarantee it will work for all the devices. So yours are far from enough.
drawable
drawable-hdpi
drawable-land-hdpi
drawable-land-mdpi
drawable-land-xhdpi
drawable-mdpi
drawable-nodpi
drawable-sw600dp-hdpi
drawable-sw600dp-land-hdpi
drawable-sw600dp-land-mdpi
drawable-sw600dp-mdpi
drawable-sw600dp-nodpi
drawable-sw600dp-xhdpi
drawable-sw720dp-hdpi
drawable-sw720dp-land-hdpi
drawable-sw720dp-land-mdpi
drawable-sw720dp-mdpi
drawable-sw720dp-nodpi
drawable-sw720dp-xhdpi
drawable-xhdpi
layout
layout-land
layout-port
layout-sw600dp-port
layout-sw720dp
layout-sw720dp-port
According to this page the layout-small,layout-normal,layout-large,layout-xlarge
are deprecated and you will use the
36x36 for low-density
48x48 for medium-density
72x72 for high-density
96x96 for extra high-density
as alernative, however for further information please check my answer here
Related
I read a lot about supporting multiple screens problems in Android, but I didn't solve mines yet. If I understood well, there are at least 2 ways to show images on different screens and to make it look normal. First, to make many images (xhdpi, hdpi, mdpi, ldpi). Second, is to create layouts(big, medium, small and etc.) My question is: which method is better? Now, my problem. I took first method, create my image in different sizes and copied to folders according to image's size. I used DEVS BITMAP app to get size, which I want my image to look like for different screens. I'm getting perfect view when I look on the 7' screen, but the view gets terrible on 3' screen. I copied this code to my Manifest:
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
I think it isn't necessary, but I wanted to be sure I am doing everything good. Could anyone answer my question and solve my problem? I would appreciate your help! ;)
Create a new Project.
There is a layout folder ,values-sw600dp,values-dw720dp-land. In both these folders, there is a dimens.xml file. What is written in it is this :-
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (`e.g. 10" tablets)` in landscape here.
-->
<dimen name="activity_horizontal_margin">128dp</dimen>
That mean folders with sw-720 dp are for 10 inch devices, similar 600dp are for 7 inch devices and default layout folders vary from 3 to 5 inch device.
layout-sw600dp -> This folder will have xml in PORTRAIL Orientation for 7 inch devices
layout-sw600dp-land -> This folder will have xml in LANDSCAPE Orientation for 7 inch devices. When you rotate your device, view will be formed from this folder
Based on the dpi/resoulution of your devices, you can create unlimited number of layout folders.
Similarly, there are folders for images called drawable ->hdpi ldpi mdpi xhdpi xxhdpi. Based on the resolution of devices, images are picked from their respective category.
xxhdpi will contain images with the highest resolution. So try to download big resolution images and downsize them and put them in the other folders.
Now how to know which device will take which image ? See the image below :-
See the drop down. It contains a list of devices with their resolutions and image type -hdpi ldpi mdpi xhdpi xxhdpi. Moreover, you can GOOGLE for the devices and their resolutions and dpi's.
So whatever app you are making for a device, choose that device and look at its resolution and see whether it is hdpi or ldpi etc. Accordingly, put the images and layouts.
This is my understanding. I create my layouts with this understanding. I hope you got a clear picture
For Multiple Screen Support
Add Different size of images to
drawable-ldpi/
drawable-mdpi/
drawable-hdpi/
drawable-xhdpi/
drawable-xxhdpi/
Suppose you have Imageview in layout folder
<ImageView
android:layout_width="#dimen/horizontal_len"
android:layout_height="#dimen/vertical_len" />
Do the following values
values/dimens.xml (Normal mobile)
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="horizontal_len">16dp</dimen>
<dimen name="vertical_len">16dp</dimen>
values-large/dimens.xml (7 inch)
<dimen name="horizontal_len">20dp</dimen>
<dimen name="vertical_len">20dp</dimen>
values-xlarge/dimens. xml (10 inch)
<dimen name="horizontal_len">22dp</dimen>
<dimen name="vertical_len">22dp</dimen>
So you have to try like this.
I started programming Android-Apps a few weeks ago. First, many thanks to all the members of this forum. Numerous posts helped me solving my problems with my app. But now, I have a problem I cannot handle and I dont find an answer.
So, what is the problem:
In my app I want to display a kind of table. On my main testing device everything fits good. But when i tried the app on an AVD with a smaller screen i realized, that the text size (in dp) is to big and the system creates a second row to display all the letters. Therefore, I decided to create an own layout for the four different classes of screen sizes with four different text sizes.
According to http://developer.android.com/guide/practices/screens_support.html and http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch and many other posts on the internet the system choose the right layout automatically.
But I assert, that it doesnt. The system always load the default layout. I cannot understand why. When I delete the default order, it always load the small layout, even on my Galaxy Note 2. And on the AVD with the smallest screen, the app is closed with an error while starting. However, the normal layout runs on the smallest screen...
I even tried this to support the layout, but no success:
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
Every xml-file has the same name. And th folders are named 'layout', 'layout-small', 'layout-large' and 'layout-xlarge'.
Can anyone help me? I guess, I just missed a little trick...
I don't think you want 'layout', 'layout-small', 'layout-large' and 'layout-xlarge'. While those do exist, they're sort of generic, and the behavior isn't as clearly defined. See this table:
http://developer.android.com/guide/practices/screens_support.html
You are using size, not density. Try these instead:`
ldpi Resources for low-density (ldpi) screens (~120dpi).
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
The resulting folders are layout, layout-ldpi, layout-hdpi, etc. This is how I've always done it and it works.
It might be more about density than size. Why don't you try instead of separating by size, to use ldpi, mdpi, hdpi, and xhdpi?
OK, I think this is the best solution...
http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf
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.
I have requirement to support all screen sizes on Android (Phones and Tablets). I have a set of images with resolutions 1280x720 and 2560x1600.
Question
How to name drawable and layout folders, so that these images are scaled correctly for all resolutions(if possible) ?
I'm clear that the question has been asked very often, but all I can find are half answers. I tried to create drawable folders with names:
drawable-xlarge-mdpi - for 1200X800
drawable-xlarge-xhdpi - for 2560X1600
And for layout, with names:
layout-xlarge-mdpi - for 1280x720
layout-xlarge-xhdpi - for 25601600
And added a manifest entry:
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
But now, it works only for tablets. On phones it always fails with error.
I found an answer here:
Drawables for qHD resolution
As I understand, all scaling occurs through code. But can anyone explain to me how to scale the image in the code with a resolution of 1280x720 and 2560x1600 and in which folder are to be placed in ?
I have read:
Application Skeleton to support multiple screen
Android : App support for multiple tablet screen resolutions
http://developer.android.com/guide/practices/screens_support.html
Android: support multiple screens
and many more.
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