Take the 2-minute tour ×

Method 'onDraw()' will be called twice when 'invalidate' is called. I want to move the view up in onDraw(),here is my code

package com.blsm.sss.view;

public class MoveRelativeLayout extends RelativeLayout {

    private int mDelta = 0;

    public MoveRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

    public MoveRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    public void move(int delta) {

        mDelta = delta;     
        Logger.d("MoveRelativeLayout", "move() delta:" + mDelta);

    protected void onDraw(Canvas canvas) {
            Logger.d("MoveRelativeLayout", "onDraw() delta:" + mDelta);
            canvas.translate(0, mDelta);

But when i call the method 'move()' onDraw will be called twice. I don't know why , can anyone help me?

share|improve this question
If you don't call invalidate(), whether the onDraw() will be called? –  yushulx Jul 30 '13 at 2:25

2 Answers 2

I don't think you need to call super.onDraw();

share|improve this answer

Is it likely that the move() method will be called from a thread other than the UI Thread? If so, I would start by using postInvalidate() and see if you get the same problem...

share|improve this answer

Your Answer


