Android Development Screen Adaptive method

Source: Internet
Author: User

Let's take a look:

is to fix Android multi-screen adaptive by setting layout_weight. The purpose of this property is to determine the display weight of the control in its parent layout, which is typically used in linear layouts.

The smaller the value, the higher the priority of the corresponding layout_width or layout_height, in general landscape layout, the decision is the priority of the layout_width, vertical layout,

The priority of the layout_height is set.


The traditional way to use layout_weight is to set the Layout_width and layout_height of the current control to fill_parent so that the control's display scale is completely given to

Layout_weight; In this case, the smaller the layout_weight, the larger the display ratio. However, for 2 controls, if the control is too large and the display is more

Example is not the same time, the control is more troublesome, after all, the inverse is not so good certainty.
So there is now the most popular 0px set value method. Seemingly incomprehensible layout_height=0px, combined with layout_weight, can make a proportional example of the control

Display, which easily solves one of the most vexing problems with the current Android development.
First look at the following styles (Style_layout.xml)

<?xml version= "1.0" encoding= "Utf-8"?><resources>   <!--full screen stretching--  <style name= "Layout_ Full ">      <item name=" android:layout_width ">fill_parent</item>      <item name=" Android:layout _height ">fill_parent</item>    </style>   <!--fix itself size--  <style name=" Layout_wrap ">      <item name=" android:layout_width ">wrap_content</item>      <item name=" Android:layout_ Height >wrap_content</item>    </style> <!--horizontal distribution--  <style name= "Layout_horizontal "Parent=" Layout_full ">      <item name=" android:layout_width ">0px</item>    </style>     <!--vertical Distribution--  <style name= "layout_vertical" parent= "Layout_full" >      <item name= " Android:layout_height ">0px</item>    </style>          </resources>  

As you can see, the two attributes of Layout_width and layout_height have been encapsulated into 4 style
According to the actual layout situation, choose one of them, do not need their own settings, see my previous Activitygroup demo students should be very familiar with
Then the layout of my demo is as follows (Weight_layout.xml)

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/                 Android "style=" @style/layout_full "android:orientation=" vertical "> <linearlayout style= "@style/layout_vertical" android:layout_weight= "1" android:orientation= "Horizontal" > <view style= "@style/layout_horizontal" Android:bac                         Kground= "#aa0000" android:layout_weight= "1"/> <view style= "@style/layout_horizontal" android:background= "#00aa00" Android:layo                         ut_weight= "4"/> <view style= "@style/layout_horizontal"                         Android:background= "#0000aa" android:layout_weight= "3"/> <view style= "@style/layout_Horizontal "android:background=" #aaaaaa "android:layout_weight=" 2 "/>                </LinearLayout> <linearlayout style= "@style/layout_vertical"                         android:layout_weight= "2" android:orientation= "vertical" > <view style= "@style/layout_vertical" android:background= "#ffffff" and                         roid:layout_weight= "4"/> <view style= "@style/layout_vertical" Android:background= "#aa0000" android:layout_weight= "3"/> <                         View style= "@style/layout_vertical" android:background= "#00aa00" android:layout_weight= "2"/> <view style= "@style/layout_vertic                     Al    Android:background= "#0000aa" android:layout_weight= "1"/> </linearlayout></ Linearlayout>

The overall layout of the interface looks very intuitive, but the nested logic should be set up for itself. Display effects such as, where the left one is 480x800 interface, the right is 320x480

Interface (also shown in the following diagram), you can see that the scale is exactly the same as in the code, such as.




































Android Development Screen Adaptive method

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.