How to place images in Android drawables - android

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.

Related

Android single screen layout for all devices

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" />

Screen Resolution for different Android Devices [duplicate]

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

Supporting Multiple Screens (2560X1600 and 1280x720)

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.

Android phones using wrong drawable folder

I currently have all the standard drawable folders set up for my app on 2.3.3. (ldpi hdpi mdpi xhdpi) However, whenever I run the app on a 240dpi screen (hdpi) it uses the resources found in drawable-mdpi not drawable-hdpi. When I delete the mdpi folder everything work perfectly. Testing on the other screen densities works great. Just not hdpi screens. Any suggestions?
I was missing some declarations in my manifest file. Adding these fixed my problem.
<uses-sdk android:minSdkVersion="4" />
AND
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
240dpi screen take only ldpi drawable folder if there is no ldpi drawable it will autometically
get mdpi drawable....
the hdpi drawable means high density pixel(480dpi)

Android - layout-large folder is been ignored

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

Categories

Resources