android - 在所有布局方法之后调用哪个 Activity 方法?

标签 android android-layout

在调用了所有布局方法、所有 View 就位并且 Activity 之后,我需要在 Activity 中做一些事情> 可以显示了。

哪种方法可以做到这一点?

最佳答案

如果您尝试获取 View 的宽度或其他内容。这应该工作

将此添加到您的 Activity 的 onCreate

ViewTreeObserver vto = layout.getViewTreeObserver(); 
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
    @Override 
    public void onGlobalLayout() { 
        // Put your code here. 

        layout.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
    } 
}); 

关于android - 在所有布局方法之后调用哪个 Activity 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7474572/

相关文章:

android - 如何在没有提示的情况下以编程方式安装 android 应用程序,

android - android内核模式获取完整包名

单击项目时的Android操作栏自定义下拉 View

android - 是否可以使 ActionBar 选项卡的高度高于 ActionBar 的高度?如果是这样,如何?

Android Activity 到 Service 类

android - ConstraintLayout 中的 RecyclerView 与其他元素重叠

android - 流音频文件,以便在Android中使用Google Drive API从Google Drive播放

android - 如何使用菜单选项从另一个 Activity 格式化一个 Activity

android - 相对布局中添加的 fragment 下方的按钮如何可点击

android - 在 Linux 上下载 Android Studio 包