In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to tune the UI of Android". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to tune the UI of Android".
1. Hierarchical analysis of the view:
For each view, you need to go through three steps: measurement, layout, and rendering. As for how App draws the view, it needs to measure from the top node and render one by one along the layout tree. The more levels of the view tree and the more times of nested measurements, the longer the measurement time. Once the measurement is finished, the layout will be carried out, and each view will lay out its own child view. After the child view is laid out, it will return to the parent view, and then to the root view. After the layout is completed, each view will be drawn on the screen.
Obviously, the more views the App has, the deeper the hierarchy, the longer it takes to measure, lay out, and draw. To reduce this time, you need to keep the view level as flat as possible and delete all views that do not need to be rendered.
Although you can view the node views of the layout in the XML layout file, it is difficult to find redundant views. In order to find these redundant views, you can use the Hierarchy Viewer tool in Android Studio to analyze the views in Android App.
Hierarchy Viewer (hierarchy Viewer) can easily view various view nesting relationships in a visual way, and can be used to study the structure of XML views. (a device running Android App is required)
With this tool, you can view the hierarchy of our View and modify our layout with it.
General advice:
The use of abstract layout tags (include, viewstub, merge) is mainly to optimize the layout and remove unnecessary nesting and View nodes.
View reuse
Mostly used in list forms such as ListView and RecylerView
Using include nested layouts to achieve modular layout design, you need to take into account the use of merge tags discussed below.
Label
After using include, the layout may be nested too much, resulting in unnecessary layout nodes, resulting in slow parsing. Unnecessary nodes and nesting can be viewed through hierarchy viewer or Settings-> developer options-> display layout boundaries. Merge tag plays a very important role in the structure optimization of UI. It can delete redundant levels and optimize UI.
Merge is often used to replace FrameLayout or when one layout contains another, the merge tag eliminates redundant view groups in the view hierarchy.
The merge tag can be used in two typical cases:
a. The layout top node is FrameLayout and there is no need to set properties such as background or padding. You can use merge instead, because the parent view of the Activity content view is a FrameLayout, so you can use merge to eliminate only one.
b. When a layout is include as a sub-layout, merge is used as the top node of the layout, so that the top node is automatically ignored when it is introduced, and all its child nodes are merged into the main layout.
Viewstub tags, like include tags, can be used to introduce an external layout, except that the layout introduced by viewstub does not expand by default, that is, it takes neither display nor space, thus saving cpu and memory when parsing layout.
Viewstub is often used to introduce layouts that are not displayed by default but only in special circumstances, such as progress layouts, refresh layouts for network failure displays, and layout prompts for information errors.
For example, suppose network_error.xml is a layout that needs to be displayed only if there is a network error, and it will not be parsed by default.
When we want to use it, there are two ways to use it, and the effect is the same:
((ViewStub) findViewById (R.id.layout_error)) .setVisibility (View.VISIBLE)
/ / or
View importPanel = (ViewStub) findViewById (R.id.layout_error) .inflate ()
II. Reduction of resources
The first point mentioned is that after flattening the view structure of App and reducing the number of views, we can actually try to reduce the number of resources used in each view. (such as referencing a resource when loading and shading at run time)
III. Overdrawing of the screen
The concept of overdrawing the screen is somewhat similar to the concept of layers in PhotoShop, where the upper layers cover the lower layers, making the lower layers invisible. When the Android system draws the screen, it first draws the parent view and then the child view, which is located on its parent view.
The act of redrawing the screen is called overdrawing, and multiple screen drawings can increase latency and can lead to layout stutters.
Since the impact of overpainting is so great, how should we detect it?
Android provides some good tools to detect overpainting, and the general way is to select "Show Overdraw area" from the Debug GPU Overdraw menu (overdraw for the debug GPU in the developer's options in my phone), and then cover different areas of App with different colors to indicate the number of overpainting. Compare these different colors on the screen to quickly locate the problem.
White: not overdrawn
Blue: overdrawn once (screen drawn twice)
Green: overdrawn 2 times
Light red: overdrawn 3 times
Crimson: overpainted 4 or more times
Another way to view it is to save view hierarchy as an Photoshop document with the help of the Hierarchy Viewer tool mentioned earlier, and you can see different levels of overdrawing when you open these views.
4. Analyze stutter (rendering ability of strategy GPU)
After optimizing the hierarchical structure of the view and overrendering, App may lose frames or become unsmooth. In order to obtain more comprehensive stutter detection information, Android system has a Profile GPU Rendering developer option, which can detect how long each frame has been used on the screen, and the policy data can be saved to a log file or displayed on the device in real time. In general, rendering data that displays GPU directly on the screen can be seen more intuitively.
In my mobile phone, find "GPU rendering Mode Analysis" in the developer options, select "display as a bar chart on screen", then open a Mobile QQ, and find the situation shown in the following figure.
What you need to pay attention to is the horizontal green line at the bottom, which indicates that the device needs to 16ms a frame, and each frame is a horizontal bar. If many frames exceed this green line, the device is stuttered.
Make it look faster
As mentioned earlier, if you find a problem in the test to optimize the layout to make UI drawing smoother, there is actually another way to make UI draw faster: make it look faster.
Progress bar
Animation
Instant update: after the user updates a page, the data on the page will change immediately, even if the data has not yet reached the server (you need to make sure that the data can eventually be updated to the server) (offline upload, offline send network request)
Or another way of thinking is to upload pictures to the server in advance when users add text about picture posts.
Thank you for reading, the above is the content of "how to tune the UI of Android". After the study of this article, I believe you have a deeper understanding of how to tune the UI of Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.