开发者

Android Layouts for Multiple Screen Sizes

开发者 https://www.devze.com 2023-02-28 01:31 出处:网络
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 \"effi

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开发者_Go百科 things?


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


For landscape and portrait mode, you can use different xmls, incase u need to display your screen according to the orientations. I have been using this method for my apps. As for support of multiple screen, you can go with relative layout as parent node. Dont go with absolute layout.


you have to take relative layout for any dynamic screen & all measurement will be in percent(%) or u can use the property(fill parent or wrap content), by do so u can somewhat manage layout for different screen

0

精彩评论

暂无评论...
验证码 换一张
取 消