android - 以编程方式删除布局

标签 android android-layout

我的应用程序 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/

相关文章:

android - 更改搜索栏拇指的大小

Android TextView 在 CoordinatorLayout 中不可选? (TextView 不支持文本选择。选择已取消)

java - 如何在android中以编程方式调用扩展RelativeLayout的类?

Android View 之上的 View

java - 从数据库填充 ListView 项时获取其 ID

java - 长按 ListView 项目时删除 ListView 项目

android - 在发布应用程序时删除 AdMob 的测试设备 ID 是个好主意吗?

完成后的Android错误()

java - 如何在一个线程中运行多个方法?

android - 如何获取/更改当前的输入语言?