2012-04-18 38 views
6

Tôi có cấu trúc xml hoạt động ứng dụng của mình sau đây. Bây giờ tôi muốn loại bỏ con RelativeLayout lập trình với id layer1Front. Làm thế nào tôi sẽ làm điều đó trong mã. Tôi không muốn ẩn nó, tôi cần phải loại bỏ nó vì các vấn đề bộ nhớ trong ứng dụng của tôi. Ngoài ra sau khi gỡ bỏ nó bằng cách nào đó ứng dụng của tôi sẽ nhẹ hơn và nhanh hơn so với hiện tại?Xóa bố cục theo chương trình

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

thể trùng lặp của [làm thế nào để loại bỏ sublayout từ Layout trong Android?] (http://stackoverflow.com/questions/4030053/how-to-remove-sublayout-from-the-layout-in-android) – SERPRO

+1

Tôi hy vọng bạn đã thử Xem .G ONE – ValayPatel

+1

Tôi không muốn ẩn bố cục. Tôi muốn xóa nó –

Trả lời

28

đơn giản nhất sẽ là

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

Nhưng sau đó bạn cũng có thể có một cái gì đó giống như

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

Không, ứng dụng của bạn sẽ không được nhẹ hơn hoặc nhanh hơn sau khi loại bỏ nó

+0

Chế độ xem xóa có xóa một số bộ nhớ không? – Raj

+0

TYPO: setVisibiliy – Andy

2

Hãy thử lấy bố trí phụ huynh và hơn loại bỏ con

parentView.remove(child) 

Tôi hy vọng công trình này.

Các vấn đề liên quan