ProgressBar sequence:
1:ProgressBar.java
1)指定attribute类型
this(context, attrs, com.android.internal.R.attr.progressBarStyle);
Attrs.xml---定义progressbar的Style属性
<attr name="progressBarStyle" format="reference" />
<attr name="progressBarStyleHorizontal" format="reference" />
<attr name="progressBarStyleSmall" format="reference" />
<attr name="progressBarStyleSmallTitle" format="reference" />
<attr name="progressBarStyleLarge" format="reference" />
<attr name="progressBarStyleInverse" format="reference" />
<attr name="progressBarStyleSmallInverse" format="reference" />
<attr name="progressBarStyleLargeInverse" format="reference" />
2)obtainStyledAttributes(attrs, R.styleable.ProgressBar, defStyle, styleRes);
Attrs.xml---定义progressbar的专有属性
<declare-styleable name="ProgressBar">
<attr name="max" format="integer" />
<attr name="progress" format="integer" />
<attr name="secondaryProgress" format="integer" />
<attr name="indeterminate" format="boolean" />
<attr name="indeterminateOnly" format="boolean" />
<attr name="indeterminateDrawable" format="reference" />
<attr name="progressDrawable" format="reference" />
<attr name="indeterminateDuration" format="integer" min="1" />
<attr name="indeterminateBehavior">
<enum name="repeat" value="1" />
<enum name="cycle" value="2" />
</attr>
<attr name="minWidth" format="dimension" />
<attr name="maxWidth" />
<attr name="minHeight" format="dimension" />
<attr name="maxHeight" />
<attr name="interpolator" format="reference" />
<attr name="animationResolution" format="integer" />
</declare-styleable>
通过Theme等对属性赋值
Theme.xml---<item name="progressBarStyle">@android:style/Widget.ProgressBar</item>
Styles.xml----
<style name="Widget.ProgressBar">
<item name="android:indeterminateOnly">true</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_medium_white</item>
<item name="android:indeterminateBehavior">repeat</item>
<item name="android:indeterminateDuration">3500</item>
<item name="android:minWidth">48dip</item>
<item name="android:maxWidth">48dip</item>
<item name="android:minHeight">48dip</item>
<item name="android:maxHeight">48dip</item>
</style>
3)通过get的attribute进行处理
其中对图像的progressDrawable
在horizontal中
<style name="Widget.ProgressBar.Horizontal">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
@android:drawable/progress_horizontal
进入frameworks/base/core/res/res/drawable/progress_horizontal.xml,里面是对graphic属性的设置
<layer-list xmlns:android=http://schemas.android.com/apk/res/android>
<item android:id="@android:id/background">--------------这个id是ProgressBar.java中用的
<shape>//开始对background层的处理
<corners android:radius="5dip" />
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">--------------这个id是ProgressBar.java中用的
<clip>//开始对background层的处理
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>
</layerlist>
其中:layer-list gradient clip等属性是graphic中处理的:frameworks/base/graphics/java/android/graphics/drawable
Tips:
大部分的改动是针对graphics,drawable的
看空间里面的头文件的定义来理解
----eg:progressbar
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.graphics.drawable.shapes.