自定义SeekBar分段显示并填充数据pop显示当前选中位置

40 篇文章 0 订阅
26 篇文章 0 订阅

最近公司项目紧张,许久没来看博客了,现在因项目需要,特将用到的控件做了个大概出来,具体效果图如下,详细细节需自己考量修改:

其实这个不是最好的。最好是全部drawing。。 我已经实现了,下次有时间再更换源码和效果图


部分代码如下:

    private Context context;

    private static final int DEFAULT_PAINT_STROKE_WIDTH = 8;

    private static final int DEFAULT_FILLED_COLOR = Color.parseColor("#FFA500");

    private static final int DEFAULT_EMPTY_COLOR = Color.parseColor("#ff0000");
    /**
     * rangebar粗细
     */
    private static final float DEFAULT_BAR_HEIGHT_PERCENT = 0.10f;

    //设置长度
    private static final int DEFAULT_RANGE_COUNT = 8;

    /**
     * rangebar高度
     */
    private static final int DEFAULT_HEIGHT_IN_DP = 90;

    /**
     * bar的填充画笔
     */
    protected Paint paint;
    protected Paint mPaint;

    private int currentIndex;

    private float currentSlidingX;

    private float currentSlidingY;

    //具体数值
    private int[] circlePositions;

    //用于绘制bar长度
    private float[] circlePositions2 = new float[DEFAULT_RANGE_COUNT];

    private int filledColor = DEFAULT_FILLED_COLOR;

    private int emptyColor = DEFAULT_EMPTY_COLOR;

    private float barHeightPercent = DEFAULT_BAR_HEIGHT_PERCENT;

    private int rangeCount = DEFAULT_RANGE_COUNT;

    private int barHeight, locationY;
    private float downX;
    private float downY;

    //
    private Bitmap bitmap_point;

    private int layoutHeight;
//    private boolean mPopupStyle;//是否显示pop

    private PopupWindow mPopup;
    View popView;
    TextView tv;
    int indexNum; //位置数值
    private int[] mPosition;

    public RangeSliderBar(Context context) {
        this(context, null);
        this.context = context;
        initPop();
    }

    public RangeSliderBar(Context context, AttributeSet attrs) {
        this(context, attrs, -1);
        this.context = context;
        initPop();
    }

    public void setContext(Context context){
        this.context = context;
    }


    public void setShowPopText(String str){
        tv.setText(str);
    }

    void initPop(){
        mPosition = new int[2];
        popView = LayoutInflater.from(context).inflate(R.layout.seekbar_pop, null);
        mPopup=new PopupWindow(popView,popView.getWidth(),popView.getHeight(),true);
        tv = (TextView) popView.findViewById(R.id.tv_showtxt);
    }
 
 
 
源码链接 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

好名字都被猪取了-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值