2012-11-14 46 views
0

我有一個活動,其中包含各種視圖(按鈕,文本等)。 我想要做的是編程擦拭一切,然後設置一些圖片的背景。當然,使用相同的活動而不切換到不同的活動。 這可能嗎?從屏幕和顯示圖像擦除所有內容

謝謝!

回答

1

如果你真的想消滅一切可以使用:

ViewGroup.removeAllViews(); 

您的根視圖在佈局中。

但你可能要考慮使用ViewSwitcher或者乾脆躲在使用

View.setVisibility(View.GONE) 

而是要能夠重複使用的內容。

0

所有的視圖必須在一些主佈局(如果沒有,把它們放在一個這樣的佈局)。給該佈局一個id,然後使用findViewById()來獲取該佈局,然後調用removeAllViews()或removeAllViewsInLayout()方法。

0

你可以在一個單一的佈局所有的視圖和佈局的可見性設置爲View.GONE並設置圖像的可見性可見

0

沒有必要實際刪除視圖。使用ViewSwitcher代替:

<?xml version="1.0" encoding="utf-8"?> 

<ViewSwitcher 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/viewswitcher" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <ImageView 
      android:src="@drawable/your_image" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 

    <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="match_parent"> 

      <!-- your views here --> 

    </LinearLayout> 

</ViewSwitcher> 

然後,在你的代碼:

ViewSwitcher vs = (ViewSwitcher) findViewById(R.id.viewswitcher); 
vs.showNext(); 
vs.showPrevious();