The Android official offers all the ways to support different screen sizes

Source: Internet
Author: User

This article will show you how to get your application to support a variety of different screen sizes, mainly through the following methods:

Allow your layout to be fully adaptive to the screen

Load the appropriate UI layout according to the configuration of the screen

Make sure the correct layout is applied to the correct device screen

Provides pictures that can be scaled automatically based on screen size

Use "Wrap_content" and "Match_parent"

To ensure that your layout adapts to various screen sizes, you should use "Wrap_content" and "Match_parent" in the layout view to determine its width and height. If you use "Wrap_content", the width and height of the corresponding view will be set to contain the minimum value of the content in the view. And if you use "Match_parent" (called "Fill_parent" before the Android API 8), you'll extend the width and height of the view to fill the entire parent layout.

By using "Wrap_content" and "match_parent" to define the size of the view in a hard-coded fashion, your view either uses just a bit of space that you need, or it fills up all the available space. For example:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation= "vertical" Androi D:layout_width= "Match_parent" android:layout_height= "match_parent" > <linearlayout android:layout_width= "ma
                  Tch_parent "android:id=" @+id/linearlayout1 "android:gravity=" center " android:layout_height= "50DP" > <imageview android:id= "@+id/imageview1" Android:layout_h eight= "Wrap_content" android:layout_width= "wrap_content" android:src= "@drawable/logo "Android:paddingright=" 30DP "android:layout_gravity=" left "Andro
              id:layout_weight= "0"/> <view android:layout_height= "wrap_content" android:id= "@+id/view1" Android:layout_width= "Wrap_content" android:layout_weight= "1"/> <button androi D:id= "@+id/categorybuttoN "android:background=" @drawable/button_bg "android:layout_height=" Match_parent " android:layout_weight= "0" android:layout_width= "120DP" style= "@style/categorybutton Style "/> </LinearLayout> <fragment android:id=" @+id/headlines "android:layout _height= "Fill_parent" Android:name= "Com.example.android.newsreader.HeadlinesFragment" Android: Layout_width= "Match_parent"/> </LinearLayout>

Note how the above example uses "Wrap_content" and "match_parent" to define the width of the control, which allows the entire layout to fit correctly to the size of different screens, or even to the horizontal screen.

The following figure shows the results of this layout in both the vertical and horizontal screens, noting that the width and height of the control are adaptive to the screen.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.