Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android devices with different height takes same layout folder

Tags:

android

layout

I have a Micromax AQ5000 with Screen Resolution- 1280*720 pixels and Motorola Moto G XT1033 with resolution 720 x 1280 pixels.I have a layout folder named layout-sw360dp which I designed for devices like Samsung s4,s3,Micromax canvas etc but this Motorola device is also using the same layout and this creates the images displayed as distorted in it.

How can I create a folder for the small device(Moto g) I tried layout-xhdpi but it doesn't work how can I name layout with height and width.

like image 655
Karthika PB Avatar asked Mar 13 '15 06:03

Karthika PB


1 Answers

Well you are right in some sense android should take layout dependent on different densities but some mobile do not fall under specific density. Therefore android will pick up default layout from layout directory.

to support multiple screen resolution provide different layout for different screen sizes, you can make following directories in res directory like this

layout-hdpi

layout-mdpi

layout-xhdpi

layout-xxhdpi

layout-w320dp-h408dp

layout-w480dp-h800dp

layout-w480dp-h854dp

layout-w720dp-h1280dp

layout-w1080dp-h1920dp

when you provide layout in all this directories you will give multiple screen support for different sizes as well layout-w1440dp-h2560dp

Use "dip" instead they will help you in debugging your layout as they will try to keep a coherent size to multiple screen resolutions,

<ImageView
            android:id="@+id/avtar_animation_11"
            android:layout_width="45dip"
            android:layout_height="45dip"
            android:src="@drawable/avtar011"/>

while supporting multiple screen when you give "dp" to dimensions, Actually android expects you to provide different values for different screen resolution. Lets say below is your imagview dimensions make few folders in res folder in your android project like these below

enter image description here

values-hdpi, values-mdpi, values-ldpi, values-xhdpi, values-xxhdpi

and in them make a dimens.xml file each of them and write

<dimen name="image_view_width">28dp</dimen>
<dimen name="image_view_height">28dp</dimen>

now that i have mentioned "dp" here instead of dip android wants me to keep track for different dimensions for different screen resolution, So i will change the image_view_width and image_view_height values are in separate values folders where dimens.xml is located. Make sure your dp values change as per your screen resolution you want your view to fit in.

 <ImageView
        android:id="@+id/avtar_animation_11"
        android:layout_width="@dimen/image_view_width"
        android:layout_height="@dimen/image_view_height"
        android:src="@drawable/avtar011"/>

hard part is over now android will pick one of dimens.xml values depending on which screen your app is running, Voila now your layout rocks

like image 121
Pankaj Nimgade Avatar answered Nov 12 '22 07:11

Pankaj Nimgade