且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

规模和对齐定制的Andr​​oid AnalogClock手

更新时间:2023-01-27 18:32:46

是这样过工作吗?尝试将它添加到时钟构造函数:
setWillNotDraw(假);

Was this ever working? Try to add this to Clock constructor: setWillNotDraw(false);

如果这种观点并没有做自己的任何绘图,设置该标志允许进一步的优化。在默认情况下,这个标志没有被设置上查看,但可以在某些视图子类,如设置的ViewGroup。通常情况下,如果重写的onDraw(android.graphics.Canvas),你应该清除该标志。

"If this view doesn't do any drawing on its own, set this flag to allow further optimizations. By default, this flag is not set on View, but could be set on some View subclasses such as ViewGroup. Typically, if you override onDraw(android.graphics.Canvas) you should clear this flag."

编辑:
如果你想重新绘制你的看法,你应该叫无效()

无效整个视图。如果视图是可见的,的onDraw(android.graphics.Canvas)将在未来的某个时刻被调用。

"Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future. "

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mChanged = true;
    this.invalidate();
}

您甚至不必调用无效();如果你只是想例如旋转视图:

You don't even have to call invalidate(); if you just want to for example rotate the view:

 @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mChanged = true;
        setRotation(20);
    }

编辑2:

当你为一个可绘制设定界限,正确的值应大于左,例如更高:
minuteHand.setBounds(X - (W / 2),Y - (H / 2),X +(W / 2)+ 4,Y +(H / 4));
要么
minuteHand.setBounds(X - (W / 2)中,y - (H / 2)中,x +(W / 2)+ minuteHand.getIntrinsicWidth()中,y +(H / 4));

When you are setting bounds for a Drawable, the "right" value should be higher than "left" for example: minuteHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2) + 4, y + (h / 4)); or minuteHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2) + minuteHand.getIntrinsicWidth(), y + (h / 4));