<?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>
<corners android:radius="5dip" />
<!-- angle 是角度 -->
<gradient
android:angle="270"
android:centerColor="#8e8989"
android:centerY="0.75"
android:endColor="#8e8989"
android:startColor="#8e8989" />
</shape>
</item>
<!-- 第一進(jìn)度條 -->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#60cae8"
android:centerY="0.75"
android:endColor="#60cae8"
android:startColor="#60cae8" />
</shape>
</clip>
</item>
</layer-list>
在xml中
<SeekBar
android:id="@+id/telescope_seekBar"
android:layout_width="250dp"
android:layout_marginLeft="60dp"
android:layout_marginTop="25dp"
android:layout_height="wrap_content"
android:thumb="@mipmap/btnzoom"http://改變進(jìn)度條上的按鈕圖標(biāo)
android:thumbOffset="0dip"http://目的是圖片和進(jìn)度條對(duì)齊
android:maxHeight="6dip"http://設(shè)置 進(jìn)度條的寬度
android:minHeight="6dip"
android:progressDrawable="@drawable/seekbar_style"/>
豎直的seekBar這樣寫
public class VerticalSeekBar extends SeekBar {
public VerticalSeekBar(Context context) {
super(context);
}
public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldw, oldh);
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
@Override
protected synchronized void onDraw(Canvas canvas) {
canvas.rotate(-90);
canvas.translate(-getHeight(),0);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()){
return false;
}
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
setProgress(getMax()
- (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
}