Android Layouts for Multiple Screen Sizes

前端 未结 3 1376
温柔的废话
温柔的废话 2020-12-10 20:06

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 o

相关标签:
3条回答
  • 2020-12-10 20:27

    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 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-10 20:36

    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.

    0 讨论(0)
提交回复
热议问题