Rotate animation android

后端 未结 4 2100
轻奢々
轻奢々 2021-02-07 01:25

I\'m trying to do a rotating image animation. I need to rotate an icon around itself just like they do in a progressbar, but what I\'m getting is an image rotat

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 01:36

    This is the source code for the layout main.xml:

    
    
    
        

    To implement the rotation animation, we can define the animation by XML or Java code. If we want to write the animation in the xml, we need to create an animation xml file under /res/anim folder. Here, we create a xml file named rotate_around_center_point.xml

    
    
    
        
    
    
    

    and this is my Activity:

    public class MainActivity extends Activity implements OnClickListener {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Button btn = (Button) findViewById(R.id.testButton);
            btn.setOnClickListener(this);
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            ImageView animationTarget = (ImageView) this.findViewById(R.id.testImage);
    
            Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point);
            animationTarget.startAnimation(animation);
    
        }
    
    
    }
    

提交回复
热议问题