[英]Android: custom seekbar thumb doesn't show correctly
I have a custom SeekBar with a specific style:我有一个具有特定样式的自定义 SeekBar:
<SeekBar
android:id="@+id/mediacontroller_progress"
style="@style/MediaSeekBar"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content" />
MediaSeekBar style: MediaSeekBar 样式:
<style name="MediaSeekBar" parent="android:Widget.SeekBar">
<item name="android:progressDrawable">@drawable/media_seek_bar</item>
<item name="android:minHeight">2dp</item>
<item name="android:maxHeight">2dp</item>
<item name="android:thumb">@drawable/media_seek_bar_thumb</item>
<item name="android:progress">0</item>
</style>
media_seek_bar drawable: media_seek_bar 可绘制:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="0dip" />
<solid android:color="#20ffffff" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="0dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="0dip" />
<solid android:color="@color/theme_accent_1" />
</shape>
</clip>
</item>
</layer-list>
media_seek_bar_thumb drawable: media_seek_bar_thumb 可绘制:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/control_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/control_pressed" />
<item android:state_selected="true"
android:drawable="@drawable/control_pressed" />
<item android:drawable="@drawable/control_normal" />
</selector>
And the result:结果:
without press没有新闻
So the problem is the area arround the yellow circle: it's translucent in my png files but not in App.所以问题是黄色圆圈周围的区域:它在我的 png 文件中是半透明的,但在 App 中不是。
Problem is in your images inside selector. 问题在于选择器内的图像。 Probably images have extra space.
可能图像有额外的空间。 I have tried to run your code with custom drawable inside selector and it works fine.
我试图用自定义drawable内部选择器运行你的代码,它工作正常。 Here my circle drawable:
在这里我的圆圈可绘制:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#ffe600"/> <size android:width="15dp" android:height="15dp"/> </shape>
<SeekBar
android:splitTrack="false"
....
/>
Will be ok. 会好的。
just set this code and work只需设置此代码即可工作
android:thumbTint="@android:color/transparent" // this code for hide thumb
android:splitTrack="false" // this code for show correctly
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.