Android 自定义SeekBar显示进度百分比,android基础知识

该博客介绍了如何在Android中创建一个自定义的SeekBar,显示进度百分比。通过设置最小值、最大值以及监听器,实现了滑动条的触摸交互,并在滑动时更新进度值,同时展示当前的进度数值。
摘要由CSDN通过智能技术生成

int max = 100;

int min = 0;

OnValueChangedListener onValueChangedListener;

public Slider(Context context, AttributeSet attrs) {

super(context, attrs);

setAttributes(attrs);

}

// Set atributtes of XML to View

protected void setAttributes(AttributeSet attrs) {

setBackgroundResource(R.drawable.background_transparent);

// Set size of view

setMinimumHeight(Utils.dpToPx(48, getResources()));

setMinimumWidth(Utils.dpToPx(80, getResources()));

// Set background Color

// Color by resource

int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,

“background”, -1);

if (bacgroundColor != -1) {

setBackgroundColor(getResources().getColor(bacgroundColor));

} else {

// Color by hexadecimal

int background = attrs.getAttributeIntValue(ANDROIDXML,

“background”, -1);

if (background != -1)

setBackgroundColor(background);

}

showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,

“showNumberIndicator”, false);

min = attrs.getAttributeIntValue(MATERIALDESIGNXML, “min”, 0);

max = attrs.getAttributeIntValue(MATERIALDESIGNXML, “max”, 0);

value = attrs.getAttributeIntValue(MATERIALDESIGNXML, “value”, min);

ball = new Ball(getContext());

RelativeLayout.LayoutParams pa
rams = new LayoutParams(Utils.dpToPx(20,

getResources()), Utils.dpToPx(20, getResources()));

params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

ball.setLayoutParams(params);

addView(ball);

// Set if slider content number indicator

// TODO

if (showNumberIndicator) {

numberIndicator = new NumberIndicat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值