When has the Activity finished drawing itself?

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

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 want 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?

回答1:

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();   } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!