How to build Animator slide up/down in XML for android?

前端 未结 1 2016
悲&欢浪女
悲&欢浪女 2020-12-18 11:30

I\'ve been trying to find out how to build an animator (xml) that will cause a slide up and slide down effect. How would that work? Thanks

1条回答
  •  臣服心动
    2020-12-18 12:11

    Make a folder anim in the res folder of the project. Now add slide_up.xml for slide_up animation. Then add slide_down.xml for slide down animation.

    Code for slide_down.xml:

      
        
    
    

    Code for slide_up.xml:

      
        
    
    

    Then load the animation in onCreate method consequently:

    Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
    

    To start it attach it to object you want to be animated:

    ImageView img = (ImageView) findViewById(R.id.img);
    img.startAnimation(slideUp);
    

    Hope I've helped you. :-)

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