This article has participated in the third “topic writing” track of the Denver Creators Training Camp. For details, check out: Digg Project | Creators Training Camp third is ongoing, “write” to make a personal impact.
π About the author
As we all know, life is a long process of constantly overcoming difficulties and reflecting on progress. In this process, there will be a lot of questions and thoughts about life, so I decided to share my thoughts, experiences and stories to find resonance!!
Focus on Android/Unity and various game development tips, as well as various resource sharing (websites, tools, materials, source code, games, etc.)
π about to learn
Learn about the options available for Android and choose the right technology.
π background
β
π Practice
π Data report
β
Adaptation has been with Android since a short time ago. There are two core issues for Android adaptation. One is efficiency, whether developers can write layout code quickly according to design drawings, and the other is how to ensure consistency in phones of different sizes and resolutions. So there are adaptations.
π Traditional adaptation
This adaptation comes with Android. DP units are used to calculate the corresponding pixels according to the resolution and size of the phone. Dp is the most basic and original adaptation of Android. We won’t discuss it too much, and there won’t be any adaptation on the market if it works.
π qualifier adaptation
In order to solve this adaptation problem, qualifier adaptation is proposed. It simply lists all the width and height pixels or the smallest size on the market.
There are two scheme width and height qualifiers and sw qualifiers
β
Then, the resolution of the target device of the product is taken as the reference system, and the smaller one is subtracted, and the larger one is added. You can Google the equations.
Disadvantages:
- Need to add a lot of files, tangible increased package size
- So many files in the dimen and so on have to be calculated to get in, there is a certain amount of work
- The fatal flaw of the width and height qualifier is that it has a poor fault tolerance mechanism, which requires accurate hit resolution to fit well. Otherwise, the default is used. The SW qualifier has fault tolerance, and if there is no corresponding one, it will look down.
How it works: Developers will generate a set of values files in advance (see above), and when the App is running the system will find the resource folder that matches the current phone resolution. If not, the width and height qualifier scheme will look for the default, and the SW qualifier will look down.
Sw qualifier schemes are recommended if they are used.
π Full screen adaptation
When the full screen first came out, it was really the full screen. Before long, a large number of new products appeared in the market, and all kinds of weird designs came out. Immediately, all kinds of APPS began to adapt to all kinds of work overnight, which was really bitter for programmers. Because when it first came out, the full-screen phone was very messy, and the adaptation scheme was full of tricks. After a period of precipitation now basically coincide with the same design principles.
The biggest difference compared to traditional screen displays is the aspect ratio. The width of the device has not changed much, but the height has increased considerably, from 16:9 for most displays to 18:9.
The first thing you see is the stretching effect of the launch page, which makes the first impression uncomfortable. (I’m not going to screenshot it. It’s too long.)
There are three solutions:
- Create drawable- xxHDpi-2140×1080 resource folder by automatically loading drawable with different resolution
- Using the.9 scheme
- Use layout + SAO operation. How? Notice that the vast majority of launch pages have solid colors at the top and bottom with no content or only content on one side. If the top and bottom colors are the same, add the same background color to the Layout. If the top and bottom colors are the same, add a View on the top and bottom of the Layout to set the corresponding color, so as to achieve the effect of false and true. So as for some design drawings up and down have content and different how to do? You can either work with the UI to fix it and make it work for each other, or you can use the method above.
β
π Bangs and splash screens
See these two articles for details:
www.jianshu.com/p/8ead0701d…
www.jianshu.com/p/62c6625db…
Xiao Kong has not done these adaptations, the company’s products do not need. Keep an open mind about this option. It occupies the status bar, so just leave it empty. Xiao Kong has used hundreds of apps and never paid attention to whether it has been adapted to this. I don’t care. What I want to see more is the APP function.
π Virtual button adaptation
Interface effect such as scenery, the key a bad mood.
The virtual buttons on most phones are pretty good right now, either translucent or hidden, with few of the big, goofy black bars that Android has by default.
You can add Settings to a topic
< itemname = “android: navigationBarColor” > set color values, such as the translucent
This approach effectively solves the problem of converting UI designs into layout code, since both are already pixels, and the application no longer needs to compute into DP units. The gap between design and code is resolved, greatly improving efficiency and productivity.
π Today’s headlines
This is the solution that we have been using for our current projects, but if you are using this solution for older projects, you may have to redo your layout sizes.
Making address:
Github.com/JessYanCodi…
The official has a good and perfect documentation, small empty is not fooling around in this.
Compared with others, SW qualifier and AutoSize are recommended as the current adaptation schemes. They have their own advantages and disadvantages, and developers can make their own choices based on practical experience.
π follow-up
Most Internet products are mobile terminals, DP can basically meet the needs, xiaokong is in a different industry, a variety of mobile phone and tablet customized devices emerge in an endless stream, so adaptation needs to be made. But the plan is that the dead are alive, so don’t limit yourself.
There is no best adaptation scheme, only the most appropriate.
π other
π’ author: Kom and Kom in Kom
π’ reprint instructions – be sure to specify the source: Zhim Granular’s personal home page – column – Nuggets (juejin. Cn)
π’ welcome to like π collect π message π