1

How to design android app for multiple screens using only one layout (not by layout_small or layout_large and so on)?

I have to achieve support for multiple screen using only one layout design.

I have read all docs from android official site but got stuck.

AADProgramming
  • 6,077
  • 11
  • 38
  • 58
  • One layout can only have one design. – Simon Jan 24 '15 at 07:45
  • i mean to say that i want my app that run on multiple android devices... – crazyAnDroid Jan 24 '15 at 07:51
  • I know, and that's why I said one layout can only have one design. It will support all screens but will look the same and will simply scale up or down. It is not possible to have different layouts for different devices without using different filenames and/or folders. Why don't you want to do this? – Simon Jan 24 '15 at 07:54
  • BTW, what is the reason why you need only 1 layout and still wants to support multiple devices? – AADProgramming Jan 24 '15 at 07:54
  • i don't want to implement it by organizing layouts like small,large,xlarge or layout_sw320dp...it will be time consuming and long operation for large application..........i have do using single layout that can support multiple screens....hope u got it ??? – crazyAnDroid Jan 24 '15 at 07:57
  • can anyone guide me with tutorial or example to achieve this? – crazyAnDroid Jan 24 '15 at 08:05
  • You can use `LinearLayout` with `weight` property. – Piyush Jan 24 '15 at 08:08
  • can u explain with any example or .tutorial? it will be very helpful for me – crazyAnDroid Jan 24 '15 at 08:14
  • It can be used simply with `LinearLayout` orientation. If the `orientation` is `horizontal` then `width` must be `0dp` and if it is `vertical` then `height` must be `0dp` while using `android:layout_weight` property. – Piyush Jan 24 '15 at 08:24
  • @ Piyush gupta: can give me one example for that or tutorial that u have used in your app? – crazyAnDroid Jan 24 '15 at 08:37
  • Check these http://www.chess-ix.com/blog/the-use-of-layout_weight-with-android-layouts/ , http://www.7solutions.in/2013/10/weightweight-sum-in-android.html , http://ugia.io/2012/01/19/android-linearlayout-distribution-explained-weight-and-sizes/ and http://blog.stylingandroid.com/layout-weights-part-1/. – Piyush Jan 24 '15 at 08:44
  • thanks @piyush :It is useful for me...;) – crazyAnDroid Jan 24 '15 at 08:52

1 Answers1

0

1) You should use wrap_content and match_parent.

2) If you have linear layout, use weightSum and weight attributes.

3) For text sizes, you can use,

<TextView android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView android:textAppearance="?android:attr/textAppearanceLarge" />

It will set text size automatically as per device density.

4) For more flexibility, you can use dimens...

res/values/dimens.xml(default)
res/values-ldpi/dimens.xml   (240x320 and nearer resolution)
res/values-mdpi/dimens.xml   (320x480 and nearer resolution)
res/values-hdpi/dimens.xml   (480x800, 540x960 and nearer resolution)
res/values-xhdpi/dimens.xml  (720x1280 - Samsung S3, Micromax Canvas HD, etc)
res/values-xxhdpi/dimens.xml (1080x1920 - Samsung S4, HTC one, etc)

P.S. 4th point is taken from this answer

Community
  • 1
  • 1
Hirak Chhatbar
  • 3,159
  • 1
  • 27
  • 36