系统自带的SeekBar真是太难看了,项目需要,只能自定义了,先来张效果图
第一个Seekbar 背景是颜色,thumb是图片,上代码:
[html] view plaincopy
- <SeekBar
- android:id="@+id/timeline"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:focusable="true"
- android:maxHeight="4.0dip"
- android:minHeight="4.0dip"
- android:paddingLeft="16.0dip"
- android:paddingRight="16.0dip"
- android:progressDrawable="@drawable/po_seekbar"
- android:thumb="@drawable/seekbar_thumb" />
drawable/po_seekbar.xml:
[html] view plaincopy
- <?xml version="1.0" encoding="utf-8"?>
- <layer-list
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@*android:id/background">
- <shape>
- <solid android:color="#ff51495e" />
- </shape>
- </item>
- <item android:id="@*android:id/secondaryProgress">
- <clip>
- <shape>
- <solid android:color="#ff51495e" />
- </shape>
- </clip>
- </item>
- <item android:id="@*android:id/progress">
- <clip>
- <shape>
- <solid android:color="#ff996dfe" />
- </shape>
- </clip>
- </item>
- </layer-list>
drawable/seekbar_thumb.xml:
[html] view plaincopy
- <?xml version="1.0" encoding="utf-8"?>
- <selector
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/seekbar_thumb_normal" />
- <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/seekbar_thumb_pressed" />
- <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/seekbar_thumb_pressed" />
- <item android:drawable="@drawable/seekbar_thumb_normal" />
- </selector>
seekbar_thumb_pressed.png:
seekbar_thumb_normal.png:
第2个和第3个seekbar都是图片实现的
[html] view plaincopy
- <SeekBar
- android:id="@+id/sb_detail_play_progress"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_gravity="center"
- android:paddingLeft="15.0dip"
- android:paddingRight="15.0dip"
- android:progressDrawable="@drawable/progress_holo_light"
- android:thumb="@drawable/detail_icon_schedule_ball" />
drawable/progress_holo_light.xml:
[html] view plaincopy
- <?xml version="1.0" encoding="utf-8"?>
- <layer-list
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@*android:id/background" android:drawable="@drawable/volumn_bg" />
- <item android:id="@*android:id/secondaryProgress">
- <scale android:drawable="@drawable/volumn_front" android:scaleWidth="100%" />
- </item>
- <item android:id="@*android:id/progress">
- <scale android:drawable="@drawable/volumn_primary" android:scaleWidth="100%" />
- </item>
- </layer-list>
volumn_bg.9.png
volumn_front.9.png
volumn_primary.png
第3个seekbar
这有个图片
demo下载链接:http://download.csdn.net/detail/w8320273/7800859
时间: 2024-11-14 07:32:16