I haven't updated my blog for a long time. I was too busy some time ago. After a while, I had a lot of new gains. Today, I will summarize the spinner image for implementing the custom progressbar. In fact, this function is very simple. I just think that sometimes it may not be possible to implement this requirement quickly. I will record it here today, it's a note.
Progressbar provides the void setindeterminatedrawable (drawabled) method to set the spinner. Remember that to use this method, you must call setindeterminate (booleanb) to study the android source code, the setindeterminatedrawable method is implemented as follows:
public void setIndeterminateDrawable(Drawable d) { if (d != null) { d.setCallback(this); } mIndeterminateDrawable = d; if (mIndeterminate) { mCurrentDrawable = d; postInvalidate(); } }
It determines the mindeterminate variable, and the setindeterminate method is used to set this variable. The source code of progressbar is not complex. You can take a look.
If we follow setindeterminatedrawable
This method may not work. I wrote it as follows:
<item> <rotate android:drawable="@drawable/loading_spinner" android:fromDegrees="0.0" android:toDegrees="360.0" android:pivotX="50.0%" android:pivotY="50.0%"/> </item>
Put it under the drawable folder. After running the file, the spinner does not turn it. I really don't know why. Finally, I read the android source code, which is written as follows:
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/loading_spinner" android:pivotX="50%" android:pivotY="50%"/>
In this way, you can write it.
Sometimes, it is very important to consider the way of thinking about the problem. When there is no way to get through, think about whether there are other ideas. Android has the source code for reference, which can help us solve many problems, haha. I will study the source code in the future.