search

Home  >  Q&A  >  body text

android - 如何在onCreate中获取view的宽高

在onCreate()回调中关于布局的信息很多都获取不到(应该是该声明周期执行的太早了,view还都没进行布局了),想问一下大家一般都是在activity的哪个声明周期获取布局信息的,或者有什么其他方法。

迷茫迷茫2772 days ago459

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 17:44:21

    Use view.post(Runnable r).
    Essentially, it is to add the task to the execution queue of the view. When this logic is executed, the previous task of the view must have been executed, and then the correct measuredSize can be obtained

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:44:21

    Under Google, Android has several ways to obtain the width and height of View

    reply
    0
  • Cancelreply