This is some bloggers own self-adaptive understanding of the Android screen, there is no place to spray.
First of all, observe the new Project Res folder, you can expect to find Drawable folder has many, such as drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi, These folders are Google for the screen self-adaptation to do the preparation, meaning that friends in the screen to adapt before you should prepare 5 sets of resource pictures to come out of the problem. The corresponding proportional relationship is probably 1:0.5:0.75:1.5:2, and now most of the 4.0 of the machine is no longer suitable for 240*320 and 320*480 screens, and turned to such as 480*800, 720*1280 and other larger screens so the plot can only do 1:1.5: 2.
Introduction asked Drawable folder down to say the values folder, the same reader can see that there are many similar folders (if not manually new is also possible), values, Values-large, values-xlarge, etc., These folders are also intended to be adapted to the size of the screen. One of the important documents is dimens.
There is the layout of multiple files, the detailed reader should be familiar with the role of these folders, here is no longer read carefully.
OK now the resources available in hand are described above and get to the point.
Bloggers in the process of dealing with screen adaptation to think of three kinds of (1) Multiple layout layouts (recommended use frequency reduction), (2) multiple sets of graphs and multiple sets of dimens with the use, (3) multiple sets of layouts, multiple sets of diagrams, multiple sets of dimens mixed use.
Method One:
Set up layout, Layout-large, layout-xlarge three folders (if you want to adapt to 240*320 and 320*480, you can also set up Layout-small, Layout-middle), Suppose you create a new Test.xml file under the Layout folder, define all the quantity values under this file as a base of 1, all the control size, spacing, fill values are all written dead, such as PADDING10, margin10,layout_width=100, etc. Under the Layout-large folder, also create a new file name and layout under the name of the file is also called Test.xml, but the file should be all the value of the layout folder under the value of 1.5 times times, so the adaptation of large screen is basically completed. According to gourd painting Scoop can also complete the large screen adaptation. After the completion of the examination, the concentration of inappropriate measures can be modified to complete the rough screen adaptive. When the project is running on the real machine, the Android system depends on the current screen size, and that set of layout resources is displayed on the screen. If you want to divide a finer reader, you can also create multiple layout resource files, adding 1.15, 1.25, 1.35, 1.45 times times layout layouts on top of the original benchmark. This way the screen adapts to perfection, and can only say that infinity is close to perfection and not perfect. This method is relatively not difficult to understand, that is, when the layout of the process is more, the work of this method will become a geometric rate of growth, it is recommended to use caution.
Method Two: A set of layout layouts, multiple sets of measures to adapt
This method of operation is relatively simple, in order to make a set layout to adapt to the 480*800 screen that is, to adapt to the benchmark screen, but all of them, such as padding, margin, width, height, textsize can not be written dead, All become reference values, reference values in the Values folder under the Dimens, Dimens file can be defined in the size and font size, such as the official given example <dimen name= "Activity_horizontal_margin >16DP</dimen> defined dimensions. The Dimens file under the Values folder has a reference set of 1, and the corresponding other dimens corresponds to 1.5 and 2. For example, in the Dimens file under Values-large <dimen name= "Activity_horizontal_margin" >24dp</dimen>, The dimens definition under Values-xlarge <dimen name= "Activity_horizontal_margin" >32dp</dimen>. In this way, the value of the control size, padding, margin, etc. should be written in a form such as android:layout_width= "@dimen/activity_horizontal_margin". is to refer to a variable as the width of the control, so that the Android system can determine how to display it itself. This method is the method that the blogger used before, the effect is good. The following illustration shows:
This is the dimens in the values directory, which defines a number of font sizes
The following is the font size defined under Values-lagre
Below is the definition of the font under Values-xlarge under Dimens
You can see that the name has not changed, but the measure has changed, so you can approximate the end of the screen adaptive problem, some other needs to change the additional settings.
Method Three: Mixed use
On the basis of the first two methods, part of the long layout, part of long variables, so that the best way to solve the adaptive method, is to do in the process of need to grasp the boundaries of the time, this method blogger is also trying, but can be expected to the benefits of this method.
Summary, often seen some articles mentioned screen density, screen size problems, bloggers feel should be to complicate the problem and pull away. Just follow Google's intentions, and it shouldn't be too much of an accident. Well, the time is not early, wash and sleep, there are questions please leave a message. Do not spray!!!
Personal insights about adaptive Android screens