2015-11-10 151 views
2

我正在創建一個設置活動,無論用戶是否能夠激活/取消激活通知。現在我想顯示/隱藏點擊切換按鈕上的某些選項。我可以隱藏視圖但不知道如何再次顯示?在這裏,我正在粘貼我的切換代碼:如何顯示/隱藏視圖/佈局在開關點擊android?

notify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(CompoundButton compoundButton, boolean b) { 
      if(b) 
      { 

       notifyMail.animate() 
         .translationY(0) 
         .alpha(0.0f) 
         .setListener(new AnimatorListenerAdapter() { 
          @Override 
          public void onAnimationEnd(Animator animation) { 
           super.onAnimationEnd(animation); 
           notifyMail.setVisibility(View.GONE); 
          } 
         }); 
       notifyPhone.animate() 
         .translationY(0) 
         .alpha(0.0f) 
         .setListener(new AnimatorListenerAdapter() { 
          @Override 
          public void onAnimationEnd(Animator animation) { 
           super.onAnimationEnd(animation); 
           notifyPhone.setVisibility(View.GONE); 
          } 
         }); 
       notifyHitcher.animate() 
         .translationY(0) 
         .alpha(0.0f) 
         .setListener(new AnimatorListenerAdapter() { 
          @Override 
          public void onAnimationEnd(Animator animation) { 
           super.onAnimationEnd(animation); 
           notifyHitcher.setVisibility(View.GONE); 
          } 
         }); 
       notifyDriver.animate() 
         .translationY(0) 
         .alpha(0.0f) 
         .setListener(new AnimatorListenerAdapter() { 
          @Override 
          public void onAnimationEnd(Animator animation) { 
           super.onAnimationEnd(animation); 
           notifyDriver.setVisibility(View.GONE); 
          } 
         }); 



      } 
      else 
      { 
       notifyMail.animate().translationY(0); 


      } 
     } 
    }); 

其餘部分將在其他部分完成{}。在此先感謝

回答

1

你隱藏自己的看法兩次(知名度和阿爾法值)!

首先你要你的視圖設置爲可見:

notifyDriver.setVisibility(View.VISIBLE); 

在這一點上的看法是可見的,但透明的,因爲阿爾法值爲0

,所以你必須設置alpha值回到1,就像你之前做過的那樣:

notifyDriver.animate().alpha(1.0f); 
+1

非常感謝你,你的解決方案工作:) – ManishNegi

1

所有您需要做的是將其設置爲可見。像這樣 notifyDriver.setVisibility(View.VISIBLE);

+0

感謝您的迴應,但我試圖讓視圖響應,但不顯示任何東西只是空白。 – ManishNegi

1

只需撥打

notifyDriver.setVisibility(View.VISIBLE); 
+0

感謝您的迴應,但我試圖讓視圖響應,但不顯示任何東西只是空白。 – ManishNegi

+0

我從來沒有遇到這種方法的問題。你能解釋一下「它使視圖響應」嗎? – ThomasThiebaud

+0

好的。看到我已經在notifyDriver/notifyHitcher中放置了一個微調器,當我點擊選擇器的工作位置時,卻沒有在屏幕上顯示控件?我希望你明白我的觀點 – ManishNegi