原文地址: 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" />