开发者

How can i find out when onDraw has finished?

开发者 https://www.devze.com 2023-03-25 05:59 出处:网络
how can I find out w开发者_如何学Chen onDraw of a View has finished? Thanks!I don\'t know what you\'re ultimately trying to achieve, but if you need to run some logic once drawing has been completed

how can I find out w开发者_如何学Chen onDraw of a View has finished?

Thanks!


I don't know what you're ultimately trying to achieve, but if you need to run some logic once drawing has been completed in an Activity, then you can call View.post(Runnable) and put your logic inside there. onDraw would have likely taken place once the code in your Runnable has been reached since it put that Runnable on the message queue.


Place a boolean member in your View class and set it to true when onDraw is called (If you simply want to be able to test that a View has drawn).

Or if you want some sort of post-draw "event" call to execute a new thread- just put it at the end of onDraw.


Another suggestion how it could be done:

public class FVRTraceAbleListView extends ListView {

ListViewListener listener;


public interface ListViewListener {
    void onPostDraw();
}

public FVRTraceAbleListView(Context context) {
    super(context);
}

public FVRTraceAbleListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public FVRTraceAbleListView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public FVRTraceAbleListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
}


public void setListener(ListViewListener listener) {
    this.listener = listener;
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);


    if (listener != null) {
        listener.onPostDraw();
    }
}

}

0

精彩评论

暂无评论...
验证码 换一张
取 消