2015-11-10 153 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