2012-04-18 14 views
6

मुझे अपनी ऐप गतिविधि की निम्न XML संरचना मिली है। अब मैं id layer1Front के साथ प्रोग्रामेटिक रूप से बाल सापेक्ष Layout को हटाना चाहता हूं। कोड में मैं यह कैसे करूं। मैं इसे छिपाना नहीं चाहता, मुझे अपने ऐप में स्मृति समस्याओं के कारण इसे हटाने की जरूरत है। इसके अलावा इसे हटाने के बाद भी मेरा ऐप वर्तमान से हल्का और तेज होगा?प्रोग्राम लेआउट को हटाएं

<?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> 
+0

संभव डुप्लिकेट के हटाने के बाद होने के लिए नहीं जा रहा है कुछ हो सकता है [एंड्रॉइड में लेआउट से सब्बाउट को कैसे हटाया जाए?] (http://stackoverflow.com/questions/4030053/how-to-remove-sublayout-from-the-layout-in-android) – SERPRO

+1

मुझे आशा है कि आपने दृश्य को आजमाया है .g एक – ValayPatel

+1

मैं लेआउट छिपाना नहीं चाहता। मैं इसे –

उत्तर

28

सरल

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

होगा लेकिन तब आप भी तरह

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

नहीं है, अपने अनुप्रयोग हल्का या तेज यह

+0

क्या दृश्य हटाने से कुछ स्मृति साफ़ हो जाती है? – Raj

+0

टाइपो: सेट विस्बिबिली – Andy

2

माता पिता लेआउट प्राप्त करने में कठिनाई का प्रयास करें और से बच्चे को निकालने के

parentView.remove(child) 

मैं इस काम करता है उम्मीद है।

संबंधित मुद्दे