Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Liquid Layout in android

I am into a project in university, I would like to know that how can I use liquid layout in android so that different screen sizes must see the application according to its resolution?

In simple words, I would like to create an application whose layout is perfect in all the type of screens :)

I know how to create it in simple html/css in websites for PCs, but how to do it in android?

Can anyone please give suggestions/help/tutorial link?

Thanks, Usman

like image 729
user712051 Avatar asked Apr 17 '11 11:04

user712051


1 Answers

Android provides "liquid" layouts out of the box - the layout dimensions and contained elements adapt to screen resolution automatically. It is gracefully handled by the Android framework. There are various kind of layouts available (LinearLayout, FrameLayout etc.) so you need to check carefully which type of layout is the best for you.

You should avoid AbsoluteLayout. While it is true it lets you specify exact locations (x/y coordinates) of its children it is less flexible and harder to maintain than other types of layouts without absolute positioning. It is now deprecated anyway.

Useful links:

  • To read more about different layouts see: http://developer.android.com/guide/topics/ui/layout-objects.html
  • Good tutorials are also available here: http://developer.android.com/resources/tutorials/views/index.html in the "Layouts" section.
  • AbsoluteLayout doc: http://developer.android.com/reference/android/widget/AbsoluteLayout.html

Update:

Layout itself will adapt to different kind of resolutions automatically but you need to keep it mind that elements contained in a layout can look differently. The same image will be smaller on high-res screen than on low-res screen. Luckily, Android provides a way to deal with this problem in a simple manner. You can supply different images depending on the resolution that a device has (this is a bit of a simplification because there are other factors eg. pixel density in addition to resolution that matters). By the same token, it is also possible to supply a different layout but it is not that common.

Links:

  • Full story on multiple screen support: http://developer.android.com/guide/practices/screens_support.html
  • Sample code: http://developer.android.com/resources/samples/MultiResolution/index.html
like image 160
youri Avatar answered Oct 23 '22 05:10

youri