Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Layouts for Multiple Screen Sizes

I'm working on an android app that we're targeting for all screen sizes? How do i go about making my layouts? Shall i make a different layout.xml for each type of screen or is there any other "efficient" way of doing things?

like image 628
Sultan Saadat Avatar asked Jan 20 '23 22:01

Sultan Saadat


1 Answers

Read Supporting Multiple Screens, specially the section "Best practices for Screen Independence".

Basic rules:

  • Use wrap_content, fill_parent, or the dp unit (instead of px), when specifying dimensions in an XML layout file
  • Do not use AbsoluteLayout
  • Do not use hard coded pixel values in your code
  • Use density and/or resolution specific resources
  • In practice, even if your layout will work on tablets, you will also want to provide different layouts for those extra large devices to enhance user experience.

Edit concerning your screenshots.

<ImageButton
        android:id="@+id/btnSubmit"
        android:src="@drawable/submit"
        android:layout_height="22dp"
        android:layout_width="85dp"
        android:layout_marginTop="15dp"
        android:layout_below="@+id/confirmpassword"
        android:layout_centerInParent="true" />

You specify here two vertical constraints that might not play well together. Instead of layout_centerInParent, try layout_centerHorizontal.

You could also give a gravity="top|center_horizontal" to your RelativeLayout. So by default the elements get centered in the view horizontally and get sticked to the top.

Also try to align firstname below btnSignin instead of username. You might be lucky.

RelativeLayout is the most complicated layout to use. If you can't get it right after some time, you could simply decide to fall back on using combinations of nested LinearLayout

like image 57
Vincent Mimoun-Prat Avatar answered Jan 25 '23 14:01

Vincent Mimoun-Prat