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.