本文将带你了解Android应用开发android实现年龄段选择器,希望本文对大家学Android有所帮助。
本文实例为大家分享了android实现年龄段选择器的具体代码,供大家参考,具体内容如下
效果就是滑动圆形按钮选择时间,废话不多说,先上工具类
import android.view.View;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.zhiziyun.dmptest.bot.R;
/**
* Created by Administrator on 2018/7/27.
*/
public class RangeSeekBar extends View {
private float lineWidth = 5.0f;
private float textSize = 25.0f;
private int inRangeColor = 0xff247ab7;
private int outRangeColor = 0xff777777;
private int textColor = 0xff247ab7;
private int textMarginBottom = 10;
private int lowerCenterX;
private int upperCenterX;
private int bmpWidth;
private int bmpHeight;
private Bitmap lowerBmp;
private Bitmap upperBmp;
private Paint inRangePaint;
private Paint outRangePaint;
private Paint bmpPaint;
private Paint textPaint;
private boolean isLowerMoving = false;
private boolean isUpperMoving = false;
private OnRangeChangedListener onRangeChangedListener;
private int paddingLeft = 50;
private int paddingRight = 50;
private int paddingTop = 50;
private int paddingBottom = 10;
private int lineHeight;
private int lineLength = 400;
private int lineStart = paddingLeft;
private int lineEnd = lineLength + paddingLeft;
private float smallValue = 13.0f;//最小值
private float bigValue = 60.0f;//最大值
private float smallRange = smallValue;
private float bigRange = bigValue;
private int textHeight;
public RangeSeekBar(Context context) {
super(context);
init();
}
public RangeSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public RangeSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
lowerBmp = BitmapFactory.decodeResource(getResources(),
R.drawable.circular);//圆形按钮图标,自己设置
upperBmp = BitmapFactory.decodeResource(getResources(),
R.drawable.circular);//圆形按钮图标,自己设置
bmpWidth = upperBmp.getWidth();
bmpHeight = upperBmp.getHeight();
lowerCenterX = lineStart;
upperCenterX = lineEnd;
lineHeight = getHeight() - paddingBottom - lowerBmp.getHeight() / 2;
textHeight = lineHeight + lowerBmp.getHeight() / 2 + 10;
}
private void initPaint() {
// 绘制范围内的线条
inRangePaint = new Paint();
inRangePaint.setAntiAlias(true);
inRangePaint.setStrokeWidth(lineWidth);
inRangePaint.setColor(inRangeColor);
// 绘制范围外的线条
outRangePaint = new
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!