开发者

When has the Activity finished drawing itself?

This maybe somewhat of a strange question but I just can`t figure it out. Basically I have a class that extends View and overrides the onDraw method so it draws a bitmap what it is called. What I wan开发者_如何转开发t to do is when by choosing a picture from a gallery, send it through and intent and draw that on the View.

The problem is that I can`t get the Activity to draw the bitmap when it is started. I try setting in in onCreate, onStart... nothing works.

It works if I set the bitmap on a button press and calling invalitate(), so I suspect that I try to draw before the Activity hasn`t finished drawing itself.

Any suggestions?


Well, if you instantiate the class that extends the View in your onCreate, that should work.

Take a look at this example:

@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set full screen view
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    customView = new CustomView(this);
    setContentView(customView);
    customView.requestFocus();
  }


Override method onWindowFocusChanged() in Activity. This is where you can be sure that views have been drawn. You can start obtaining the dimension/ position of the views in this method. For eg. customView.getLeft(), etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜