我的应用程序 Activity 具有以下 xml 结构。现在我想以编程方式删除 ID 为 layer1Front 的子 RelativeLayout。我将如何在代码中做到这一点。我不想隐藏它,由于我的应用程序中存在内存问题,我需要将其删除。此外,在以某种方式删除它之后,我的应用程序会比当前应用程序更轻更快吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layer1Front" >
</RelativeLayout>
<HorizontalScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/parallaxLayers"
android:visibility="gone">
</FrameLayout>
</HorizontalScrollView>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/frontView">
</RelativeLayout>
</RelativeLayout>
最佳答案
最简单的是
findViewById(R.id.layer1front).setVisibility(View.GONE);
但是你也可以有类似的东西
View root = findViewById(R.id.your_root);
root.removeView(yourViewToRemove);
不,您的应用在删除后不会变得更轻或更快
关于android - 以编程方式删除布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10211252/