seekBar改变样式

<?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>

    <!-- 第一进度条 -->

    <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"//改变进度条上的按钮图标
      android:thumbOffset="0dip"//目的是图片和进度条对齐
      android:maxHeight="6dip"//设置 进度条的宽度
      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;
    }
}
QQ截图20171115204324.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容