2017-02-13 62 views
0

在一個按鈕後,銷燬佈局我打電話,像這樣的佈局:使用的setContentView

setContentView(R.layout.my_form); 

另外我想摧毀佈局。我該怎麼做 ?

+0

設置另一個佈局沒有意見添加更改其可見或者可以稱之爲rootView.removeAllViews(); –

+0

你可以給我一個如何定義rootView的例子嗎? – Rosenberg

+0

rootView是你最上面的佈局 –

回答

0

U可以使用rootView.removeAllViews();以去除佈局中的所有視圖,例如

您的佈局是

   <LinearLayout 
       android:id="@+id/llRootView" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

          ....... 

      </LinearLayout> 

然後就可以調用​​從這個線性佈局

編輯刪除所有的意見

臨時從佈局移除視圖喲ü可以使用

llRootView.setVisibility(View.GONE); 

使其可見再次使用

llRootView.setVisibility(View.VISIBLE); 
+0

要聲明它,我會這樣做,LinearLayout rootView =(LinearLayout)findViewById(R.id.llRootView)。那是對的嗎 ? – Rosenberg

+0

是的,它是正確的 –

+0

嗨,所以,它清除屏幕,刪除所有視圖**,但**佈局。我試圖做[代碼](http://prntscr.com/e87roi)涉及父佈局,但它崩潰。 – Rosenberg