Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ProgressBar to realize Color gradient in Android

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use ProgressBar to achieve color gradient in Android". In daily operation, I believe that many people have doubts about how to use ProgressBar to achieve color gradient in Android. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt of "how to use ProgressBar to achieve color gradient in Android". Next, please follow the editor to study!

First, we implement the layout above, with a gray background, a ProgressBar centered and a TextView below the ProgressBar.

The code is as follows:

The rest of the code above is easy to understand, except that ProgressBar has an indeterminate that needs to be explained:

General ProgressBar is used to show the loading progress, if we up to the current specific progress, that property should be set to true, and set the correct progress, if we do not know the correct progress, then set to false.

Once the layout is set, the next step is to set the gradient style of ProgressBar. Here we need to customize a Drawable.

The custom Drawable code is as follows:

Let's explain the above code:

The outer rotate indicates that this is a rotating animation, and the start and end angles are specified, and the center of rotation is the center of the circle.

The shape of the inner layer defines the shape as a ring with three attributes:

InnerRadiusRatio is the ratio of the outer ring radius to the inner diameter. For example, if the outer ring radius is 30 and the inner ring radius is 10, the ratio is 3.

ThicknessRatio is the ratio of the outer ring radius to the ring thickness.

If useLevel is true, it can be used in LevelListDrawable

The next gradient defines the gradient effect, defines the color at the beginning and end, and specifies that the gradient mode is scan gradient.

Finally, we set the style we defined above through a property of ProgressBar:

Android:indeterminateDrawable= "@ drawable/loading_drawable" so far, the study on "how to use ProgressBar to achieve color gradient in Android" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report