Android imagebuttons showing up different on different screens - android

I have my Android activity using the XML file below. It shows up fine on the Nexus 7 as the image attached shows but on a smaller screen like Galaxy Nexus, it isn't that good. Can someone please give me a step by step answer of how to solve this issue its very annoying. I know about multiple screen size support using the XDHPI, HDPI .... resource folders. If I put the right image sizes in the folders, will the image correct itself and what are the dimensions I should use to resize the images?
An example of what I am talking about is shown here:
At the moment, all the files are in drawable HDPI at 125 x 125 sizes please help is very appreciated.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/textbody"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="#+id/Appts"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="267dp"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/stock_appointment_reminder"
android:padding="10dp"
android:text="APPTS"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Sputum"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_below="#+id/Appts"
android:layout_toLeftOf="#+id/Data"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/micro"
android:padding="10dp"
android:text="SPUTUM"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Blood_Sugars"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/Sputum"
android:layout_toRightOf="#+id/Sputum"
android:background="?android:attr/selectableItemBackground"
android:drawablePadding="2dp"
android:drawableTop="#drawable/magnifying_glass"
android:padding="10dp"
android:text="FEV1%"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Meds"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_alignBaseline="#+id/Blood_Sugars"
android:layout_alignBottom="#+id/Blood_Sugars"
android:layout_alignParentLeft="true"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/therapist"
android:fadingEdge="horizontal"
android:padding="10dp"
android:text="MEDICINE"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Settings"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_alignLeft="#+id/Excercise"
android:layout_alignParentRight="true"
android:layout_below="#+id/Excercise"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/application_x_desktop"
android:padding="10dp"
android:text="SETTINGS"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Events"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_above="#+id/Meds"
android:layout_toRightOf="#+id/Appts"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/events"
android:padding="10dp"
android:text="EVENTS"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Data"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_above="#+id/Settings"
android:layout_alignParentRight="true"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/hitchhikeguidetogalaxy3_info"
android:padding="10dp"
android:text="MY DATA"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Contacts"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_above="#+id/Meds"
android:layout_alignParentRight="true"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/contacts_1"
android:padding="10dp"
android:text="CONTACTS"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Excercise"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Meds"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/symptom"
android:padding="10dp"
android:text="SYMPTOMS"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="#+id/Meals_Snacks"
android:layout_width="201dp"
android:layout_height="123dp"
android:layout_above="#+id/Settings"
android:layout_alignLeft="#+id/Events"
android:background="?android:attr/selectableItemBackground"
android:drawableTop="#drawable/apple"
android:padding="10dp"
android:text="NUTRITION"
android:textColor="#android:color/primary_text_dark"
android:textSize="14sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:src="#drawable/icon" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="myCF Home"
android:fontFamily="sans-serif-thin"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="50sp"
android:textStyle="bold" />
</RelativeLayout>

If you want to support multiple screen or want to make your app compatible to all screen size then first thing that you have keep in mind, never use hard-coded value for width and height.
Avoid this:
android:layout_width="201dp"
android:layout_height="123dp"
Use:
android:layout_width="wrap_content" or "match_parent"
android:layout_height="wrap_content" or "match_parent"
For more details see here: read this
In order to support all screen size you have to read support multiple screen size
Android provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_image.png // bitmap for medium density
res/drawable-hdpi/my_image.png // bitmap for high density
res/drawable-xhdpi/my_image.png // bitmap for extra high density
Use this in android manifest file in order to support multiple screen:
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />

In android you have the option hdpi, mdpi, xdpi,etc..
folders for that , you have to create different images according your device resolution and put your images at there after confirming your device resolution and density category.
for the more reference why it'll happen you can see here
here i explain some chart may be helpful to you.
Low density Small screens QVGA 240x320 (120dpi):
layout-small-ldpi (240x320)
layout-small-land-ldpi (320x240)
Low density Normal screens WVGA400 240x400 (x432) (120dpi):
layout-ldpi (240 x 400 )
layout-land-ldpi (400 x 240 )
Medium density Normal screens HVGA 320x480 (160dpi):
layout-mdpi (320 x 480 )
layout-land-mdpi (480 x 320 )
Medium density Large screens HVGA 320x480 (160dpi):
layout-large-mdpi (320 x 480 )
layout-large-land-mdpi (480 x 320)
Galaxy Tab ( 240 dpi ):
layout-large (600 x 1024)
layout-large-land (1024 x 600)
High density Normal screens WVGA800 480x800 (x854) (240 dpi):
layout-hdpi (480 x 800)
layout-land-hdpi (800 x 480)
Xoom (medium density large but 1280x800 res) (160 dpi):
layout-xlarge (800 x 1280)
layout-xlarge-land (1280 x 800)

Related

Which qualifiers should I use for supporting my layouts for different phones screens?

I have some problems with supporting my layouts for different phone/tablet screensizes. My layouts dosn't fit or scale on all screens probably. Some screen sizes give too much space and other dosn't have room for all views.
I have tried to generate different layouts with different qualifiers like: densities, dimensions and sizes in PX and with large/small/x-large qualifiers.
But I can't really figure out what qualiferes I should use to completely fit all screens.
This is a description of how my layouts behave with different screens (tested with genymotion emulator)
480px x 800px 240dpi (S3 Mini): Views dosn't fit in heights.
480px x 800px 120dpi: (Emulator): Views dosn't fit in heights
480px x 800px 320dpi: Too much free space around the views.
600px x 1024px 240dpi: Perfect fit!
600px x 1024px 420dpi: There is almost no space to show anything. maybe 2-3 views at max
1440px x 2560px 560dpi: a little bit of free space
1440px x 2560px 640DPI: Perfect fit!
1440px x 2560px 320DPI: Too much free space around the views
Here is screenshots examples of how the layout Stats scale with different screens:
Samsung S3 MINI: 480px x 800px 240dpi: https://www.dropbox.com/s/kvxggql80ivcmlp/galaxys3mini.png?dl=0
Samsung Galaxy S7: 1440px x 2560px 640DPI: https://www.dropbox.com/s/ivjd6a0zgc81oqy/galaxys7.png?dl=0
Nexus 9 API 23 2048x1536 xhdpi:https://www.dropbox.com/s/r70h4da1xcf2lhi/nexus9.PNG?dl=0
What qualifiers should I use?'
The layouts xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/arion_darkblue">
<TextView
android:id="#+id/stats_title"
style="#style/fragment_titles_style"
android:layout_alignParentTop="true"
android:text="Stats" />
<RelativeLayout
android:id="#+id/statsgroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/stats_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp">
<ImageView
android:id="#+id/stats_distance_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="#drawable/ic_stats_distance" />
<TextView
android:id="#+id/stats_distance_txt"
style="#style/fragments_textstyles"
android:layout_below="#id/stats_distance_img"
android:text="0,0 Km" />
<ImageView
android:id="#+id/stats_jump_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="35dp"
android:layout_toRightOf="#id/stats_distance_txt"
android:background="#drawable/ic_stats_jump" />
<TextView
android:id="#+id/stats_jump_txt"
style="#style/fragments_textstyles"
android:layout_below="#id/stats_distance_img"
android:layout_marginLeft="35dp"
android:layout_toRightOf="#id/stats_distance_txt"
android:text="00" />
<ImageView
android:id="#+id/stats_transition_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="65dp"
android:layout_toRightOf="#id/stats_jump_txt"
android:background="#drawable/ic_stats_transition" />
<TextView
android:id="#+id/stats_transition_txt"
style="#style/fragments_textstyles"
android:layout_below="#id/stats_distance_img"
android:layout_marginLeft="80dp"
android:layout_toRightOf="#id/stats_jump_txt"
android:text="00" />
<ImageView
android:id="#+id/stats_intensity_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_toRightOf="#id/stats_transition_img"
android:background="#drawable/ic_stats_intensity" />
<TextView
android:id="#+id/stats_intensity_txt"
style="#style/fragments_textstyles"
android:layout_below="#id/stats_distance_img"
android:layout_marginLeft="55dp"
android:layout_toRightOf="#id/stats_transition_txt"
android:text="0000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/stats_symmetric_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/statsgroup1"
android:layout_marginTop="50dp"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<TextView
android:id="#+id/stats_sym_txt1"
style="#style/fragments_textstyles"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:text="50%" />
<ImageView
android:id="#+id/stats_symmertic_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/stats_sym_txt1"
android:background="#drawable/ic_stats_symmetric" />
<TextView
style="#style/fragments_textstyles"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/stats_symmertic_img"
android:text="50%" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
<TextView
android:id="#+id/stats_rotation_txt1"
style="#style/fragments_textstyles"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:text="50%" />
<ImageView
android:id="#+id/stats_rotation_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/stats_rotation_txt1"
android:background="#drawable/ic_stats_rotation" />
<TextView
android:id="#+id/stats_rotation_txt2"
style="#style/fragments_textstyles"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/stats_rotation_img"
android:text="50%" />
</RelativeLayout>
</RelativeLayout>
Have you heard about using several dimens.xml file?
Having different dimens but one layout
That way you could have one layout, but could define sizes of elements from different dimens.xml-s which are describing dp sizes separately for each size you'd like to support.
Example from the offical android page:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textview_height">25dp</dimen>
<dimen name="textview_width">150dp</dimen>
<dimen name="ball_radius">30dp</dimen>
<dimen name="font_size">16sp</dimen>
</resources>
Then you can use these values from the layout:
<TextView
android:layout_height="#dimen/textview_height"
android:layout_width="#dimen/textview_width"
android:textSize="#dimen/font_size"/>
If you have several dimens.xml but only one layout.xml for a page, it's easier to change them consistently.
Design layout for tablet sizes
Also, consider checking the smallestWidth resource using for tablet sizes, you can handle larger screens easily width this, adding dimens.xml and/or layout to folders like layout-sw600dp/ and values-sw600dp/.
More info here

Android Imageview is getting small

I am making an android application in which I am using an ImageView.My image is displaying perfectly on Normal phone screen,
but on big screen devices like Tabs, it is getting smaller and on the left side of the screen.So what is the most appropriate solution for the same?
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#550e8c" >
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#550e8c"
android:text=""
android:textColor="#e2ffff" />
<Button
android:id="#+id/help"
android:layout_width="52dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView2"
android:background="#550e8c"
android:drawableLeft="#drawable/help1" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl"
android:background="#E5E3E4"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/home"
android:adjustViewBounds="true"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="52dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#781a8f"
android:drawableLeft="#drawable/earthnew1"
android:drawablePadding="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="#string/aware_patient"
android:textColor="#e2ffff"
android:textStyle="bold" />
<Button
android:id="#+id/btnCardiology_updates"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
android:background="#781a8f"
android:drawableLeft="#drawable/updates1"
android:drawablePadding="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="#string/Cardiology_updates"
android:textColor="#e2ffff"
android:textStyle="bold" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
android:background="#781a8f"
android:drawableLeft="#drawable/linknew1"
android:drawablePadding="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="#string/useful_links"
android:textColor="#e2ffff"
android:textStyle="bold" />
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
android:background="#781a8f"
android:drawableLeft="#drawable/linknew1"
android:drawablePadding="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="#string/Useful_journlas"
android:textColor="#e2ffff"
android:textStyle="bold" >
</Button>
</LinearLayout>
</RelativeLayout>
You have used an image named home in same resolution for different drawable folder.
For supporting tablets also, use large, xlarge qualifiers. Nexus 7 is a large-hdpi tablet(technically it's tvdpi, but takes images from hdpi). So if you want to put images for Nexus 7, make a folder named drawable-large-hdpi and put the images there.
Now regarding the 10 inch tablets case, they are xlarge devices and their densities can change from mdpi to xhdpi(Nexus 10). But many have resolution of 1280 * 800 and they are mdpi devices.
Create drawable folder like this
// for Phones
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
//for 7 inch tablets
drawable-large-ldpi
drawable-large-mdpi
drawable-large-hdpi(for Nexus 7)
// for 10 inch tablets
drawable-xlarge-mdpi
drawable-xlarge-xhdpi(for nexus 10)
Create home.png for different resolution. Here is the list of resolution for whole screen slice your image according to your requirement
320 X 480 for mdpi
480 X 800 for hdpi, large-ldpi
600 X 1024 for large-mdpi (7 inch tablet)
720 X 1280 for xhdpi (s3, nexus 4)
800 X 1280 for large-hdpi, xlarge-mdpi (nexus 7, other 10 inch
tablet)
1080 X 1920 for xxhdpi (s4, s5, nexus 5)
2560 X 1600 for xlarge-xhdpi (nexus 10)
You are using the Image view inside the Linear Layout, evethough the imageview width is wrap_content the layout width is fill_parent. Change this as wrap_content...
Like This
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rl"
android:background="#E5E3E4"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/home"
android:adjustViewBounds="true"/>
</LinearLayout>
issue is that you are putting same image in each folder. As Tablet and phone has different resolution you need different resolution image for them. If you using same image then you will face issue in one of the device.
You need to use Linear layout and Image view with fill_parent or weight option , and use margin from left , right , bottom and top . so your image view and linear layout will expand according to your screen resolution .

how to make 256 ppi avd in new version avd android

i want to make avd for Moto E device specification but for moto e device has 256 ppi pixel density so when i create avd in new version there are no any option for make custom avd with custom ppi see below image.
Any idea how can i make Moto E device avd?
EDIT
In 480 x 800 resolution device
In 540 x 960 resolution device
in my dimen.xml i give value
<dimen name="text_normal">10sp</dimen>
my row.xml is look like below
<LinearLayout
android:id="#+id/itemLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#drawable/selectore_listview"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/drawer_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:src="#drawable/drawer_properties" />
<TextView
android:id="#+id/drawer_itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/drawer_icon"
android:text="dfdsjgfhgdj"
android:textSize="#dimen/text_big_normal"
android:textColor="#android:color/white"
/>
<TextView
android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/img_add_rbn"
android:layout_alignTop="#+id/img_add_rbn"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="#+id/img_add_rbn"
android:background="#drawable/rect_counter"
android:gravity="center"
android:text="00"
android:textSize="#dimen/text_normal"
android:textColor="#android:color/white"
/>
<ImageView
android:id="#+id/img_add_rbn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginRight="50dp"
android:gravity="center"
android:src="#drawable/drawer_rbn_addnew"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
and i set this value in counter value of manage property which is gray in my image so you can see difference in 480x800 screen it look nice but in 540x960 it comes very small so any idea how can i solve it?.
There is no option for ppi because android devices are scaled in density(dpi).
Instead what you need to do is to find a dpi for your device which has 256ppi,540x960, and 4.3 in size.
Here is the sample of it taken from wiki
11 (4.3) 540x960 101 (256) 1.5 hdpi
That device is using hdpi as density which is equivalent to 256ppi that you are trying to find.
I found solution for 540 x 960 resolution device value.xml . i make folder file for 540x960 resolution device as values-sw360dp and inside it i make dimens.xml file for that and it is working for me.
by using below formula i create value folder for 540 x 960 device
px=540 width of device
dp=240 density of device
dp=(px/dp)*160
=(540/240)*160
=360
so finally create values folder like values-360dp for 540x960 device. And you can create other folder fo rmaking combination of screen width and density of device and make UI interface good for that.
for 480x800 devcie
res/values-hdpi/dimens.xml
for 540x960 device
res/values-sw360dp/dimens.xml

how to distinguish two different android mdpi phones

Im trying to write app witch will look similar on all (or most) android phones. I have a problem with two phones: Samsung Galaxy Ace 2 and Samsung Galaxy mini 2. Layout that takes whole screen in galaxy ace is too large for galaxy mini.
First I tried to specify different dimens for ldpi and mdpi, but it appeared that both phones used mdpi values. Then I was trying too distinguish them by screen sizes and made folder values-normal-mdpi. I thought that ace should be "large", it has 480x800 resolution and should be large accordinng to documentation: Supporting Multiple Screens.
However both phones take values from the "normal-mdpi" folder. On the other hand I have seen application that look identical on both phones, how can I do this?
Edit:
imagine I have a very simple layout only with simple views:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /></LinearLayout>
The last button is not visible on smaller phone. What shoud I do if I want this to look identical on both?
Well, it turns out that none of the two is an mdpi device:
Samsung Galaxy Ace 2: WVGA (480x800) resolution (about 244 dpi) = hdpi
Samsung Galaxy Mini 2: QVGA (240×320) resolution (about 127 dpi) = ldpi
So, the drawable folders for your graphics should be:
res/drawable-ldpi
res/drawable-hdpi
Please note that you should provide pngs at the proper resolutions (120 and 240 dpi).You can choose to provide a normal resolution graphics (160 dpi, which is mdpi) and it will be scaled to 120 dpi (0.75x) for ldpi devices and to 240dpi (2.0x) for hdpi devices
I think is a very good practice the use of dimensions but you must choose your classifiers properly. You must know that ldpi, mdpi, hdpi, xhdpi and xxhdpi stand for the density of pixels in the screen of devices.
In this case you're exposing, you may wanna try the "smallest width" classifier. For example, if you have 2 screens, both mdpi, but one of them is 240 dips width and the other is 320 dips, you should place dimensions under the folders "values-sw240dp" and "values-sw320dp".
Hope it helps.
You shouldn't really need to use different dimensions for different screen sizes, except in special cases. Instead, use the attributes in your layout.xml to define how the elements in your layout should scale. For instance, android:layout_width = "match_parent" will always match that element's width to the width of the parent, no matter what the screen size. Check out this link about xml layouts to get started.

android density independence

I created a layout with the prebased (480x800) density. I have been using this since I started learning android (9 mths) and now it was time to test my app on other phones. I tested it on three phones with 480x800 resolution and was fine, until I tested it on one with 320x480 and 240x320. I have used px-s as width and height, paddingTop etc. everywhere.
I checked the app in the emulator (created different avd-s for different resolutions) and I cannot see the whole layout, as it is bigger than the screen (testing it only in eclipse). It has 4 images with "wrap_content" width and height settings.
So I checked the android documentation. I have not created other layouts or anything else, but replaced the px-s with dp-s. It is the same.
I created smaller buttons (see below) with 190x60px resolution and put them into the ldpi folder, but there was no big advance. Maybe because the textsizes of the textviews are the same and the 2 textviews takes 1/3 of the place of the display in case of the 240x320 resolution (while only 1/6 in case of the 480x800). (So the texts look huge in the small resolution compared to the large resolution)
Please tell me what should I do to make the layout look in this 320x480 resolution like in the 480x800.
Size of gradientbg: this is an .xml file for a shape, so no physical size.
Size of buttons (images): 380x150px hdpi (or 190x60px in ldpi folder)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/gradientbg"
>
<TextView
android:id="#+id/TextView00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#E30000"
android:textColor="#FFFFFF"
android:gravity="center_horizontal|center_vertical"
android:textSize="26dp"
android:height="40dp"
android:textStyle="bold"
android:text="Main menu"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="App"
android:textSize="30dp"
android:textStyle="bold"
android:paddingTop="20dp"
android:layout_gravity="center_horizontal"
android:textColor="#FFB300"
/>
<Button android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mainbutton_1"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
<Button android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mainbutton_2"
android:layout_gravity="center_horizontal"
android:paddingTop="5dp"
/>
<Button android:id="#+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mainbutton_3"
android:layout_gravity="center_horizontal"
android:paddingTop="5dp"
/>
<Button android:id="#+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mainbutton_4"
android:layout_gravity="center_horizontal"
android:paddingTop="5dp"
/>
</LinearLayout>
When you normally define layouts in dp units, you ensure that the layout stays the same on devices in the same density bucket. But when you try it on a tablet (xlarge) or a small screen, it won't scale right. This tool is made to have your app work with the whole range of devices (small/normal/large/xlarge). It scales your layout xml-files from the baseline density you were originally designing for.
http://onemanmobile.blogspot.com/2012/04/how-to-scale-your-android-layouts-to.html

Categories

Resources