Android自定义View标识当前选中的控件(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-06 18:19 点击:次
selected = 0;
invalidate();
}
public void previous() {
if (selected > 0)
selected--;
else
selected = count - 1;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setAntiAlias(true);
// 起始位置,实现整体居中
float w = canvas.getWidth() - (count * 2 * radii) - space * (count - 1);
for (int i = 0; i < count; i++) {
if (i == selected)
paint.setColor(point_seleted_color);
else
paint.setColor(point_normal_color);
canvas.drawCircle(w / 2.f + radii + i * (space + radii + radii),
radii + 1, ((int) radii + 2) / 2, paint);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(widthMeasureSpec, (int) (radii * 2) + 2);
}
public void setSelected(int selectedId) {
if (selectedId >= 0 && selectedId <= count)
this.selected = selectedId;
else if (selectedId < 0)
this.selected = 0;
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>