原文地址: http://www.eoeandroid.com/blog-600773-5417.html
碰到的問題有secondaryProgress無顯示效果、seekBar高被擠壓變形、Thumb有偏移,顯示效果不理想等...
解決方法在下面的代碼裏有註釋
新建android:progressDrawable的style文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 背景圖,不可加clip屬性,否則無顯示效果 -->
<item android:id="@android:id/background">
<inset
android:insetBottom="5dip"
android:insetTop="5dip" >
<shape>
<solid android:color="#40ffffff" />
</shape>
</inset>
</item>
<!-- 第二進度條,增加inset屬性可以避免thumb上下被擠壓遮住,三處都要寫 -->
<item android:id="@android:id/secondaryProgress">
<clip>
<inset
android:insetBottom="5dip"
android:insetTop="5dip" >
<shape>
<solid android:color="#7affffff" />
</shape>
</inset>
</clip>
</item>
<!-- 第一進度條,必須放在第二進度條的下面,否則會被第二進度條覆蓋掉而看不到效果 -->
<item android:id="@android:id/progress">
<clip>
<inset
android:insetBottom="5dip"
android:insetTop="5dip" >
<shape>
<solid android:color="#ff4094eb" />
</shape>
</inset>
</clip>
</item>
</layer-list>
使用:
<!-- thumb引用的是兩張圖片,分別是自然和按下狀態的,加上thumbOffset就是往SeekBar起點左移的距離,可以調整未與起點對齊的情況,加上pading可以避免thumb兩邊被遮住的情況 -->
<SeekBar
android:id="@+id/seekBar"
android:layout_width="wrap_content"
android:layout_height="19dip"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/totalTime"
android:layout_toRightOf="@+id/currentTime"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:progressDrawable="@drawable/video_seekbar_style"
android:thumb="@drawable/video_seekbar_thumb_style"
android:thumbOffset="4dip" />