我找不到如何更改ProgressBar
動畫師,所以我建議你用你自己的drawable去。
繪製進步爲矩形
在一個簡單的例子,讓我們的進步看起來像一個矩形:
res/drawable/vector_drawable_progress_indeterminate_horizontal.xml
(名稱由core/res/res/drawable/vector_drawable_progress_indeterminate_horizontal.xml啓發)
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="10dp"
android:width="100dp"
android:viewportHeight="10"
android:viewportWidth="100" >
<group
android:name="rect1_grp"
android:scaleX="1" >
<path
android:pathData="M 0,0 h 100 v 10 h -100 Z"
android:fillColor="?attr/colorControlActivated" />
</group>
</vector>
動畫水平刻度
當然,這個矩形根本沒有動畫,所以你想把它包裝在一個對象中它是水平尺度(scaleX
的rect1_grp
)。
res/drawable/custom_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<animated-vector android:drawable="@drawable/vector_drawable_progress_indeterminate_horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<target
android:animation="@anim/progress_indeterminate_horizontal_rect1"
android:name="rect1_grp"/>
</animated-vector>
是剩下的唯一要做的,就是要有自己的動畫:
res/anim/progress_indeterminate_horizontal_rect1
:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="1500"
android:propertyName="scaleX"
android:valueFrom="0"
android:valueTo="1"
android:valueType="floatType"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
動畫線性地從0F至1F增長規模,並且以反向模式無限重複(避免有兩個動畫師序列:一個用於縮放增量,一個用於decr緩解)。
享受
現在,所有你需要做的就是在res/layout/activity.xml
使用此繪製:
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="8dip"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/custom_progress" />
剩下要做的
- 我扯下了進展到最低限度。您可能想要繪製背景。您可能還想要恢復次要進度。
- 您可以在動畫中自定義插補器。
來源
2017-02-04 19:27:08
rds
從'風格繼承什麼樣的價值觀=「機器人:ATTR/progressBarStyleHorizontal 「'? –
@TimCastelijns:其實我不知道。這是標準的Android家長。我不知道,如何看看這個值: -/ – longilong
你看看這個:http://stackoverflow.com/a/6450417/1185737 – KunalK