android - 如何在 Android 中从另一个 View 膨胀另一个 View

标签 android android-layout glsurfaceview

我知道在我的 onCreate() 中,我可以通过类似以下的方式从 XML 扩展 View :

loadingScreen = (RelativeLayout) findViewById(R.id.loadingScreen);

但是我怎么能从另一个角度做到这一点呢?我试图通过将其可见性从 GONE 设置为 VISIBLE 来调用加载屏幕,但似乎无法从我的 glSurfaceView 中弄清楚如何执行此操作

最佳答案

如果你想扩充布局,代码如下所示:

LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout myRoot = new LinearLayout(context);
View itemView = inflater.inflate(R.layout.layout_details, myRoot);

在这里,您首先创建一个新的 LinearLayout,然后将 ID 为 R.layout.layout_details 的布局膨胀到其中。然后 inflate 方法返回 myRoot View 。

这是关于 LayoutInflater 的教程:

关于android - 如何在 Android 中从另一个 View 膨胀另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7034453/

相关文章:

android - 在 Android 中操作自定义 GLSurfaceView

android - 将 Firebase 通知的 MessageBody 显示为 Toast

Android:如何使用换行内容避免在圆形按钮的圆圈外按下?

android - 如果某些 View 可见性在约束布局中消失,如何将约束设置为不同的 View ?

android - UnityPlayer 作为具有透明背景的 subview ? (统一游戏引擎)

android - SurfaceView 还是 GLSurfaceview?

android - 如何在 Xamarin.Android 应用程序上集成新的 Google 登录?

android - 在 Android 中处理 unix 信号

android - 未在 UI 编辑器 android 上指定 Intellij 设备

android - ScrollView 中的全屏布局