6

私は自分のアプリアクティビティの次のxml構造を持っています。ここで、idlayer1Frontを使用してプログラムで子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>
4

2 に答える 2

31

最も単純なのは

findViewById(R.id.layer1front).setVisibility(View.GONE);

しかし、あなたはまた、次のようなものを持つことができます

View root = findViewById(R.id.your_root);
root.removeView(yourViewToRemove);

いいえ、アプリを削除した後、アプリが軽くなったり速くなったりすることはありません

于 2012-04-18T14:24:56.307 に答える
2

親のレイアウトを取得してから、子を削除してみてください

parentView.remove(child) 

これがうまくいくことを願っています。

于 2012-04-18T14:21:14.963 に答える