首先声明,这份代码是我在原博主的代码上进行了一些修改,原博客链接:
https://www.cnblogs.com/zhujiabin/p/5697255.html
我修改部分后实现的功能为:
下面直接简单粗暴的贴代码,其实就是修改一些长宽的参数,即可达到效果。
package com.example.dengfugui.flat.provider;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Px;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import com.example.dengfugui.flat.R;
import java.util.ArrayList;
public class RulerSeekBar extends View {
private final String TAG = "CustomSeekBar";
private int width;
private int height;
private int upX = 0;
private int upY = 0;
private int moveX = 0;
private int moveY = 0;
private int perHeight = 0;
private Paint mPaint;
// private Paint mTextPaint;
private Paint buttonPaint;
private Bitmap thumb;
private Bitmap spot;
private Bitmap spot_on;
private int cur_sections = 5;
private ResponseOnTouch responseOnTouch;
private int bitMapHeight = 38;//第一个点的起始位置起始,图片的长宽是76,所以取一半的距离
// private int textMove = 60;//字与下方点的距离,因为字体字体是40px,再加上10的间隔
private int[] colors = new int[]
{getResources().getColor(R.color.theme_yellow)
, Color.parseColor("#d8d8d8")};//进度条的橙色,进度条的灰色,字体的灰色
// private int textSize;
private ArrayList<String> section_title = new ArrayList<>();
public interface ResponseOnTouch {
void on