1

hey guys i have this code will hide a button and then re display it what i want is to hide it without re displaying it here is the code that i use:

 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/linear_interpolator">
   <alpha
   android:fromAlpha="1.0"
   android:toAlpha="0.1"
   android:duration="500"
   android:repeatCount="1"
   android:repeatMode="reverse" />
   </set>
Dexter90
  • 69
  • 2
  • 14

2 Answers2

2

Change this to:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
   <alpha
       android:fromAlpha="1.0"
       android:toAlpha="0.1"
       android:duration="500"
       android:repeatCount="0"
       android:fillAfter="true"
   />
</set>

This will cause the animation to hide button, and not repeat in reverse mode to show it again.

Read repeatMode and repeatCount for clearing doubt and better understanding.

Hope this helps.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
  • :( no its not going like what i want is to totally disappear this also make the button visible again – Dexter90 Sep 02 '14 at 10:23
  • @Dexter90 Make sure you have not used [setFillAfter](http://developer.android.com/reference/android/view/animation/Animation.html#setFillAfter%28boolean%29)(true). – MysticMagicϡ Sep 02 '14 at 10:24
  • @dexter do you want to fade out then the btn should be there?? – Toppers Sep 02 '14 at 10:24
  • @Dhruti no i am not using this method should i used – Dexter90 Sep 02 '14 at 10:31
  • @Toppers there is four button in my activity what i am doing is whenever i click on a button the three other button should be hided and then go to another activity that what i am trying to do :) – Dexter90 Sep 02 '14 at 10:32
  • Yes. `android:fillAfter="true"`. Add this line in xml. @Dexter90 – MysticMagicϡ Sep 02 '14 at 10:33
  • @Dhruti sorry for my question but i am really new to android in which XML file in the animation file ? – Dexter90 Sep 02 '14 at 10:34
  • @Dhruti one more question can we have a method to let some action to wait before another action – Dexter90 Sep 02 '14 at 10:44
  • 1
    You mean something like [animation listener](http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html)? @Dexter90 – MysticMagicϡ Sep 02 '14 at 10:45
  • @Dhruti i implement animation listener and when animation start i started another animation i want when the other animation finish to start another activity i will mention the code in another comment to let you understand more – Dexter90 Sep 02 '14 at 10:54
  • @Dhruti animTranslate.setAnimationListener(new Animation.AnimationListener() { public void onAnimationStart(Animation animation) { windows_phone.startAnimation(Hide); C_sharp.startAnimation(Hide); Website.startAnimation(Hide); try { startActivity(new Intent("com.f5.Android_page")); } catch (Exception ex) { Toast.makeText(getApplicationContext(), ex.toString(), Toast.LENGTH_SHORT).show(); } } – Dexter90 Sep 02 '14 at 10:55
  • put startAnimation code in `onAnimationEnd` instead of `onAnimationStart` @Dexter90 . – MysticMagicϡ Sep 02 '14 at 10:56
  • @Dexter90 I guess you would have to post a new question and put whole code their maintaining what you need to do. – MysticMagicϡ Sep 02 '14 at 11:01
  • And see [my other answer](http://stackoverflow.com/questions/24861323/sound-with-animation-in-android/24861397#24861397) if that solves your issue. @Dexter90 – MysticMagicϡ Sep 02 '14 at 11:03
  • @Dhruti did that happen to you ? http://stackoverflow.com/questions/25624137/exception-when-trying-to-put-in-my-activity-any-type-of-edittext – Dexter90 Sep 02 '14 at 13:05
0

Try this to fade out and leave the visibility as visible to button

<?xml version="1.0" encoding="utf-8"?>
  <set xmlns:android="http://schemas.android.com/apk/res/android">  
       <alpha android:fromAlpha="1" android:toAlpha="0"           
          android:duration="@*android:integer/config_shortAnimTime" />
  </set>

and then add this to your button

      Animation slide = AnimationUtils.loadAnimation(activity, R.anim.fadeout); //the above transition
     yourBtn.startAnimation(slide);
Toppers
  • 559
  • 3
  • 11
  • 1
    yup change the duration .... you can add your own or refer http://developer.android.com/reference/android/R.integer.html and FYI if you want to reverse the animation i.e fade in then just change android:fromAlpha="0" and android:toAlpha="0".....simple – Toppers Sep 02 '14 at 10:45
  • Oh thanks very much i will check it i would like to hear your point of view in the previous answer in the comment i mentioned a problem can you help me with that ? – Dexter90 Sep 02 '14 at 10:57
  • @dexture just to confirm...it seems that you want wait to execute another action until your animation finish...right?? – Toppers Sep 02 '14 at 11:04
  • yeah exactly that what i want :D – Dexter90 Sep 02 '14 at 11:12
  • i am trying to put another question but they told me every 90 min why this rule? – Dexter90 Sep 02 '14 at 11:16
  • Dexter90 @Dhruti solution http://stackoverflow.com/questions/24861323/sound-with-animation-in-android/24861397#24861397 is right.....you can add your method in onAnimationEnd(Animation animation) it will be called once your animation will finish.. – Toppers Sep 02 '14 at 11:19