Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - common techniques for scaling screen layouts

I realise this topic has been covered to death, and I have read the official and unofficial developer guides on it so know the theory. But I'm still unsure which path to take to ensure my app looks good on multiple screen sizes. My app is a simple navigation style app which is designed to be portrait only. At this stage I'm not interested in making different designs for landscape or multi-pane screens for tablets etc. I just want each screen to be scaled up/down so it looks in proportion with the screen size it is being displayed on - i.e. text and images are sized up/down as appropriate. I designed the app for a classic 480x800 hdpi device which it looks great on, I just want to make it look in proportion for the Galaxy S3/Nexus 7 etc. I'm already following these guidelines :

  • Using RelativeLayouts
  • Using DP units for padding/margins
  • Using SP units for fonts
  • Using 9-patch images for buttons

However I'm finding it still looks small and a bit lost in the middle of the screen on the larger devices. In particular, my main menu screen is a grid of 6 image buttons which I can't get to scale well. I don't want to have multiple copies to maintain of the same screen (normal/large/xlarge), just want one layout. I was considering the following :

  • Using value-normal/value-large etc. folders to store XML files with DP/SP values for sizes of images/text
  • Changing RelativeLayouts to LinearLayouts with weights (although I initially struggled with LinearLayouts and changed to RelativeLayouts

Are either of these valid approaches, or is there a better approach?

like image 535
Jonathan Wareham Avatar asked Feb 14 '13 10:02

Jonathan Wareham


People also ask

How do I make my Android apps fit all screen sizes?

The best way to create a responsive layout is to use ConstraintLayout as the base layout in your UI. ConstraintLayout enables you to specify the position and size of each view according to spatial relationships with other views in the layout. All the views can then move and resize together as the screen size changes.

How are Android layouts optimized?

Use compound drawables - A LinearLayout which contains an ImageView and a TextView can be more efficiently handled as a compound drawable. Merge root frame - If a FrameLayout is the root of a layout and does not provide background or padding etc, it can be replaced with a merge tag which is slightly more efficient.

What is the best way to increase layout display speed?

Layout performance slows down due to a nested LinearLayout and the performance can be improved by flattening the layout, making the layout shallow and wide rather than narrow and deep. A RelativeLayout as the root node allows for such layouts.


1 Answers

Personally, I would go with the first option. While this will work well for phones, it will make the layout seem somewhat bloated on tablets. Hence, another approach would be to create separate layouts for tablets and place them in the layout-large and layout-xlarge folders for 7" and 10" tablets respectively.

like image 194
Praveen Janakarajan Avatar answered Oct 22 '22 07:10

Praveen Janakarajan