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 > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to gracefully load the relevant knowledge from the network in android, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this android article on how to elegantly load from the network. Let's take a look.
1 background 1.1 what is a point nine picture
In fact, the point nine picture is not much different from the pictures in other formats we use, except that the pure black (# FF000000) lines of 1px are added around the picture. For example:
Mark position meaning left-black line longitudinal stretch area-black line horizontal stretch area right-black line vertical display area-black line horizontal display area 1.2how does Android load the point nine diagram
When we put the point nine image in the res directory, Android does not load the point nine image directly, but converts it to another format when compiling, this format is to save the black pixels around it in the byte [] array of mNinePatchChunk in the Bitmap class, and remove the width of the four Monday pixels; when in use, when judging that mNinePatchChunk is not empty and 9patchchunk, then construct it to NinePatchDrawable, otherwise construct it to BitmapDrawable, and finally set it to view. Therefore, the final packaged point-nine picture is no longer the original point-nine picture with black lines.
2 use the pit encountered in scenario 2.1
If no processing is done, when we directly pull the image of point 9 from the server and set it to our view, we find that the image will not stretch and the black lines around the image will be displayed. From the principle of loading the point nine diagram on 1.2Android, we can see that the reason for this problem is that we lack the compilation step and directly set the original point nine diagram to the view, so there is a problem. After knowing the cause of the error, we can deal with it in the following ways:
Let the product or designer convert first (the conversion tool is provided by the developer) and then upload it to the server. At this time, what the client pulls from the server is the compiled figure.
Upload the original point 9 image to a conversion platform, and then upload it to the server after conversion.
The other is that the client gets the original point nine image and then constructs the NinePatchDrawable according to the loading principle. This process is obviously too time-consuming to render on the client side and does not meet the requirements. Let's take the QQ solution as an example (the first) to discuss the implementation scheme.
2.2 use plan
First, take a look at the general flow chart:
Considerations for using the above scheme:
Step 2 the black line must be pure black pixels, and the four corners of the picture must be transparent pixels, otherwise Android will not recognize it and will not be able to convert in step 3
In step 3, you can use Android SDK's native tool aapt to convert: aapt c-v-S. -C.\ output, of which. Represents the current directory, and.\ output represents the target directory
In step 4, the converted image cannot be compressed during the upload process, because the black line information of the converted point nine image is saved to the auxiliary data fast of the png picture, and this part of the data will disappear in the process of compression, resulting in that the final picture pulled by the client is not a point nine picture.
In step 4, some cdn compress or transcode the image to webp format for traffic saving or other reasons, which will result in the final image pulled is not a point nine image.
In step 8, you need to create a drawable through Bitmap. If you use the res directory, the Android system will do it automatically. If you want to obtain a network image, you need to create it manually, as follows:
In step 9, be sure to use caching, otherwise there will be a problem in list during asynchronous loading, and the jump will be very serious.
This is the end of the article on "how to gracefully load nine pictures from the network in android". Thank you for reading! I believe that everyone has a certain understanding of "how to elegantly load nine pictures from the network in android". If you want to learn more, you are welcome to follow the industry information channel.
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.