您好,我尝试自定义搜索栏。
这是我的问题:
main.xml
...
<SeekBar android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:thumb="@drawable/seekbarthumb"
android:progressDrawable="@drawable/sb2"
android:minHeight="45dip"
android:maxHeight="45dip"
></SeekBar>
...
@drawable 中的 sb2.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/seekbarbg">
</item>
<item android:id="@android:id/progress"
android:drawable="@drawable/sb_progress">
</item>
</layer-list>
一切正常,但 sb_progress 位置错误。
所以我有两个解决方案。更改 sb_progress 的位置或使用 Photoshop 编辑 sb_progress 并添加透明像素来修复它。
通过尝试改变位置的好方法,出现了问题:
我在 sb2.xml 中添加了一些行
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/seekbarbg">
</item>
<item android:id="@android:id/progress" >
<inset
android:drawable="@drawable/sb_progress"
android:insetTop="11dip"
android:insetBottom="11dip"
android:insetLeft="11dip">
</inset>
</item>
</layer-list>
我添加了 inset元素,但结果是 suxx。位置是正确的,但进度不再有动画效果。 sb_progress.png 始终完全绘制,并且不会停在拇指处。
我需要帮助!这是一个错误吗?我需要添加透明像素吗?不是
InsetDrawable 是 Drawable 的子类。为什么搜索栏不再适用于 InsetDrawable。
java.lang.Object ↳ android.graphics.drawable.Drawable ↳ android.graphics.drawable.InsetDrawable
最佳答案
我知道这是一个老问题,但如果有人通过搜索引擎找到这个问题(就像我一样),您所需要做的就是向可绘制对象添加一个“剪辑”以及一个插图。
<item android:id="@android:id/progress" >
<clip>
<inset
android:insetRight="11dp"
android:insetLeft="11dp">
<shape>
<solid android:color="#343434"/>
</shape>
</inset>
</clip>
</item>
关于android - Seekbar 和 InsetDrawable 获取进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5514236/