2016-02-27 74 views
0

上午在Android應用程序中工作,其中有兩個活動是主要活動和模式活動。我的第一個活動是主要活動有一些隱形圖標,enter image description here 第二個活動是模式活動。當我點擊按鈕時,我的第二個活動enter image description here我回顧了我的第一個活動,我希望看不見的圖標應該可見。 enter image description here如何在android中的可見佈局

enter code here 

    pro.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      autobtn.setImageResource(R.drawable.auyto); 
      pro.setImageResource(R.drawable.proactiv); 
      Intent it = new Intent(ModeActivity.this, Mainactivity.class); 
      startActivity(it); 
     } 
    }); 

回答

1

您可以使用

yourView.setVisibility(View.GONE); 

您可以通過使用findViewByID :) 得到引用您的視圖中隱藏視圖,當你想要把它找回來只是說yourView.setVisibility(View.VISIBLE);

由於根據你的問題,在你的模式活動的onCreate或onStart你可以隱藏你的隱形圖標,如

@Override 
    protected void onStart(){ 
     super.onStart(); 
     yourView.setVisibility(View.GONE); 
    } 

並且在模式活動按鈕的onClickListener中,您可以使該按鈕可見。在onclickListener您的按鈕,把你想要的圖標顯示和隱藏對相同的按鈕(按鈕使用像切換)備用水龍頭代碼

yourView.setVisibility(View.VISIBLE); 

那所有。如果然後把下面的代碼

if (yourView.getVisibility() == View.VISIBLE) { 
     yourView.setVisibility(View.GONE); 
    } else { 
     // Either gone or invisible 
     yourView.setVisibility(View.VISIBLE); 
    } 

希望它能幫助:)

+0

我在哪裏可以在主要活動中使用這些代碼是它的onResume( ) –

+0

你可以把它放在onStart中,就像我已經顯示的那樣,或者在你想要的任何地方創建onCreate :)只要確保在調用yourView.setVisibility(View.VISIBLE)之前獲得對圖標的引用;你的視圖是你的圖標:) –

+0

每當你的主要活動被加載onStart()和onCreate在你的情況下被調用:)所以它可以把它放在這個方法中的任何一個:)任何具體的爲什麼你想把它放在onResume ??它應該在那裏也很好:) –

0

爲了讓您圖標可見,你可以使用

icon.setVisibility(View.VISIBLE); 
0

我認爲你正在使用SurfaceView,如果是,那麼讓你的SurfaceView中的FrameLayout,並通過SurfaceView地方的另一個View

喜歡這個

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

    <SurfaceView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:gravity="bottom" 
     android:orientation="horizontal" 
     > 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_logo"/> 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_logo"/> 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_logo"/> 


    </LinearLayout> 


</FrameLayout> 
+0

我該如何解決它 –

+0

只是重疊你的SurfaceView與另一個查看 – Kushal

+0

其確定請請看看我的照片,我張貼在第一圖片有隱藏按鈕,當我點擊親在我的第二張圖片我回來了第一個活動,我想這些按鈕,我在紅色方塊顯示它 –