The 'onDraw ()' method will be called twice when 'invalidate' is called

The onDraw () 'method 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; invalidate(); Logger.d("MoveRelativeLayout", "move() delta:" + mDelta); } @Override protected void onDraw(Canvas canvas) { Logger.d("MoveRelativeLayout", "onDraw() delta:" + mDelta); super.onDraw(canvas); canvas.translate(0, mDelta); } } 

But when I call the ' move() ' onDraw , it is called twice. I don’t know why, can anyone help me?

+4
source share
2 answers

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

0
source

I do not think you need to call super.onDraw ();

-1
source

All Articles