Control definition and magical techniques for progress bar types in Android

Source: Internet
Author: User

The progress bar control in Android has 3 (not progressdialog), respectively, is Progressbar,seekbar and Ratingbar, for the custom style to be divided according to the requirements of 2, the first is the scale type, the second is the loop type.

The first is "scale", that is, he has a start and end point, the starting value is less than the end point value

This style of modification, to modify the three properties can be

are: Background (mostly progress track style), first level scroll bar progressdrawable, second level progressdrawable


Unfortunately, Android provides an API that is difficult to set up, but can be implemented via layerlistdrawable, as shown in Ratingbar or Seekbar below.

<?xml version= "1.0" encoding= "Utf-8"?> <layer-list xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:id=" @+android:id/background "android:drawable=" @drawable/unselect "></item> <item android:id= "@+android:id/secondaryprogress" android:drawable= "@drawable/unselect" ></item> < Item android:id= "@+android:id/progress" android:drawable= "@drawable/selected" ></item> </layer-list >

<style name= "Roomratingbar" parent= "@android: Style/widget.ratingbar" > <item name= "android: Progressdrawable "> @drawable/ratingbar_drawable</item> <item name=" Android:minheight ">48dip</ item> <item name= "Android:maxheight" >48dip</item> </style>

<?xml version= "1.0"  encoding= "Utf-8"? ><linearlayout xmlns:android= "http// Schemas.android.com/apk/res/android "    android:layout_width=" Fill_parent "     android:layout_height= "fill_parent"     android:orientation= "vertical"   >    <ratingbar        android:layout_width= "Match_parent"         android:layout_height= "Wrap_content"          style= "@style/roomratingbar"          android:layout_marginleft= "10dip"         android:id= "@+id/ Ratingbar "        android:rating=" 1.5 "         android:stepsize= "0.15"         android:numstars= "8"     /></linearlaYout> 


The second is the loop type, no scale type

In this case, this is an animated effect, and is a reciprocating house loop, so it is suitable to do no progress of the scroll bar, loading effect, even can be used as a class rotation avatar, or other animation bar.

Therefore, this is suitable for Infinite loop frame animations or rotational animations.

We can modify

Android:indeterminatedrawable= "" android:indeterminateduration= "1000"

Android:indeterminatedrawable the value of the frame animation, you do not need to set the android:indeterminateduration, if it is another motion tween, you need to set up android: Indeterminateduration

Frame animation

<animation-list xmlns:android= "Http://schemas.android.com/apk/res/android"      Android:oneshot= "false"     android:visible= "true"  >    < item        android:drawable= "@drawable/common_loading_icon1"          android:duration= "/>    <item "        android:drawable= "@drawable/common_loading_icon2"          android:duration= "/>    <item   "      android:drawable= "@drawable/common_loading_icon3"          android:duration= "/>    <item     "    android:drawable= "@drawable/common_loading_icon4"          android:duration= "/&GT;&NB"Sp;   <item        android:drawable= "@drawable/ Common_loading_icon5 "        android:duration="/>     <item        android:drawable= "@drawable/common_loading _icon6 "        android:duration="/>    < item        android:drawable= "@drawable/common_loading_icon7"          android:duration= "/></animation-list>"

<progressbar android:layout_width= "34DP" android:layout_height= "30DP" Android:layout_c Entervertical= "true" android:layout_marginleft= "8DP" android:indeterminatedrawable= "@drawable/commo N_loading_icon "/>

Motion Tweens:

<rotate xmlns:android= "http://schemas.android.com/apk/res/android" android:drawable= "@drawable/window_loading "android:pivotx=" 50% "android:pivoty=" 50% "android:repeatmode=" reverse "android:repeatcount=" infinite "and roid:fromdegrees= "0" android:todegrees= "android:duration="/>

<progressbar android:layout_width= "60dip" android:layout_height= "60dip" android:indeterminate= "tr        UE "style="? Android:attr/progressbarstylesmall "android:indeterminatedrawable=" @anim/base_loading_anim " android:indeterminateduration= "" android:padding= "10dip"/>


Imageview+clipdrawable+handler/thread

In addition, for a crop (coffee cup is gradually full of animation) is animation, many developers generally choose frame animation, there is a better way to use Imageview+clipdrawable+handler/thread instead, For clipdrawable, the default maximum level is 10000:

We can set the height of a cropped picture to match the dark gray background, and then set the level value of the clipdrawable to ImageView

About clipdrawable See the blog: http://my.oschina.net/ososchina/blog/346562


The simplest scroll bar

Since speaking of animation, animation can completely simulate the scroll bar, do not believe you try, for the scroll bar you can also use the Linearlayout+view way to achieve (can achieve vertical or horizontal), or directly using the drawing method is also OK.


About the relative position of the animation

1. The most problematic place to learn about animation is the relative point, here by the way, the relative point determines the frame of reference of the animation. For XML, the following properties are set to automatically convert relative points

android:pivotx= "" Relative x Position [float][fraction]android:pivoty= "" Relative y position [float][fraction]

Where Android:pivotx is a real number, it is relative to its own point, such as:android:pivotx= "0.5",android:pivoty= "0.5" or android:pivotx= "50", the location of the "android:pivoty= " relative to the animation itself, is generally the center of its own

2. Animations relative to the screen

Android:pivoty= "50%p", android:pivotx= "50%p", this point thing relative to the screen, 50% means the middle of the screen.


Try doing it




Control definition and magical techniques for progress bar types in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.