Moving an image through a linearlayout

后端 未结 4 1568
一生所求
一生所求 2021-01-27 02:48

I\'m developing an Android 2.2 application.

I want to move an image from left side of the screen to the right side of the screen.

How can I do that? I\'ve read t

4条回答
  •  无人及你
    2021-01-27 02:59

    you have to use Translate Animation. For example, this animation would move an image from Left side of the screen to the right side of the screen.

    The AnimationActivity is

        listener = new AnimationListener() {
            @Override 
            public void onAnimationStart(Animation animation) {}
            @Override 
            public void onAnimationRepeat(Animation animation) {}
            @Override
            public void onAnimationEnd(Animation animation) {
                System.out.println("End Animation!");
                //load_animations();
            }
        };
    
         }
       @Override
       public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v==button)
        {
            moveLefttoRight = new TranslateAnimation(0, 200, 0, 0);
            moveLefttoRight.setDuration(1000);
            moveLefttoRight.setFillAfter(true);
            my_image.startAnimation(moveLefttoRight);
        }
        }
    
      }
    

    xml code is

     
    
    
    
    
    

    and anim file is

      
      
    

    may be this is the answer what you are searching.

提交回复
热议问题