2

I went through the Developer documents,partly understood the LDPI,HDPI,MDPI,XHDPI analogy, searched everywhere on the net but could not find specific answers.

I have two phones, one has a small screen and one is a tablet. I want the buttons on my small screen phone look small and the same buttons on the big screen look more big and occupy more space. How do I achieve this? Any tutorials?

(I place drawables in specific drawable folders and huge buttons are displayed on my small screen) Confused!

I also created different layouts specifying the DPI, what I dont understand is that if the DPI of my small screen and big screen is same, the layout will be distorted on the bigger or conversly the smaller one!

Heretic Monk
  • 397
  • 1
  • 5
  • 19

3 Answers3

2

apparently you have a lot to learn on the resources as overall, but specifically for buttons you might want to look into using a shape drawables (for simple backgrounds) or 9 patch for more complex ones as those solutions stretch much more efficiently than standard PNG backgrounds.

http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

http://developer.android.com/tools/help/draw9patch.html

google around you'll find good resources on the and even some tools to automate the creation of those resources.

Budius
  • 39,391
  • 16
  • 102
  • 144
0

read this http://developer.android.com/guide/practices/screens_support.html and check the size qualifiers section

eg, from the same link

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)
Gaurav Vashisth
  • 7,547
  • 8
  • 35
  • 56
  • And how do you determine the DP? If I have two phones with same dp but one falls in small screen and one falls in large screen!? – Heretic Monk Oct 26 '12 at 09:56
  • You are wrong `layout-sw600dp` will not going to support 7" tablet with 600dp width and even `layout-sw720dp` will not going to support 10" tablet with 720dp width. – Mohammed Azharuddin Shaikh Oct 26 '12 at 10:07
  • Eternal confusion in case of layouts Android has! – Heretic Monk Oct 26 '12 at 10:18
  • @HereticMonk dp is a unit, and is defined as: A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way. What you are confusing with is with screen-density which can by ldpi, mdpi, hdpi, xhdi or other. For example hdpi tablet you can define your layouts in res/layout-hdpi-sw720dp or for mdpi tablet res/layout-mdpi-sw720dp – Gaurav Vashisth Oct 26 '12 at 10:29
  • Consider I have a tablet 320 dpi and I have a small screen phone 320 dpi. Which implies the button size on both of them will be the same? Even if I design different GUI's for them separately, the spacing will be alright but the size wont! – Heretic Monk Oct 26 '12 at 10:35
  • keep height and width values for button in values-xhdpi-720dp/dimens.xml and values-xhdpi/dimens.xml for tablet and phone respectively – Gaurav Vashisth Oct 26 '12 at 10:40
  • Yup, sw selector is the way to go here. Don't take sw600 & sw720 as hard limits : they are very good starting point but the real question is what are the dimensions that your layout need. – Teovald Oct 26 '12 at 11:10
0

Why not to go for nine-patch images ? Here is the Android Asset Studio.

It helps you to create nine-patch images instantly . Here it is some useful information regarding nine patch. Just go through it .... Hope it helps...

AndroidLearner
  • 4,500
  • 4
  • 31
  • 62