When has the Activity finished drawing itself?

后端 未结 2 1091
傲寒
傲寒 2020-12-12 01:33

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 wha

相关标签:
2条回答
  • 2020-12-12 02:07

    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 讨论(0)
  • 2020-12-12 02:26

    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();
      }
    
    0 讨论(0)
提交回复
热议问题