How to do a fadein of an image on an Android Activity screen?

后端 未结 4 1518
别跟我提以往
别跟我提以往 2020-12-02 07:45

I\'d like to display a photo on an Android Activity screen with doing gradual and continual fade-in from pale monotone sepia to the final full color. I know how to do it on

相关标签:
4条回答
  • 2020-12-02 08:01

    I wanted an image to fade (and then disappear) once clicked from full opacity to 0. Here is how I did it:

    Animation a = new AlphaAnimation(1.00f, 0.00f);
    
    a.setDuration(1000);
    a.setAnimationListener(new AnimationListener() {
    
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub
    
        }
    
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub
    
        }
    
        public void onAnimationEnd(Animation animation) {
            yourView.setVisibility(View.GONE);
    
        }
    });
    
    yourView.startAnimation(a);
    
    0 讨论(0)
  • 2020-12-02 08:09

    Another much simpler solution is to just put a stub onClick method to your ImageView you want to fade, then inside the method you add this:

    view.animate().alpha(0).setDuration(2000);      
    
    /* Alpha attribute translates to opacity. 
    A solid View means that the alpha attribute is set to 1 (which is the 
    default) and completely invisible is 0 */
    
    0 讨论(0)
  • 2020-12-02 08:19

    One method for this would be to use the animation set. See here;

    http://developer.android.com/guide/topics/resources/available-resources.html#animation

    Some example code I have done (infinite loop fade out in this example) ;

    In the animation .xml file;

    <alpha android:fromAlpha="1.0" 
           android:toAlpha="0.3"  
           android:duration="7000"
           android:repeatMode="restart"
           android:repeatCount="infinite"/>
    

    In the java file;

     ImageView introanim = (ImageView) findViewById(R.id.introanim);
        Animation StoryAnimation = AnimationUtils.loadAnimation(this, R.anim.intro_anim);
        introanim.startAnimation(StoryAnimation);
    

    You could fade from your sepia background/picture to whatever you want...

    0 讨论(0)
  • 2020-12-02 08:28

    Hi Hiroshi you can do this for the fade in:

      ImageView myImageView= (ImageView)findViewById(R.id.myImageView);
      Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
      myImageView.startAnimation(myFadeInAnimation); //Set animation to your ImageView
    

    and inside your res\anim\ folder the animation file fadein.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
            <alpha 
                android:fromAlpha="0.0" 
                android:toAlpha="1.0"
                android:interpolator="@android:anim/accelerate_interpolator"
                android:duration="3000"/>
    </set>
    

    but for the gradual fade in from sepia to the full color, you must use TransitionDrawable

    0 讨论(0)
提交回复
热议问题