首页 > 其他 > 详细

图片无限旋转动画

时间:2015-03-18 02:15:59      阅读:338      评论:0      收藏:0      [点我收藏+]

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 图片无限旋转动画

? ? ? 平时喜欢拿着手机去听歌,看到qq音乐中有一个图片绕着中心无限旋转 的动画,于是自己动手写了个,给大家分享下。

? ? ?1 xml布局

?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.rotateanimate.MainActivity" >

    <Button
        android:id="@+id/btn_start"
        android:text="动画开始"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <ImageView
        android:id="@+id/iv_sharp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
         android:scaleType="center"
        android:src="@drawable/shape" />

</RelativeLayout>

?2 动画的配置

?

<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <rotate  
        android:fromDegrees="0"  
        android:toDegrees="360"  
        android:duration="5000"  
        android:repeatCount="-1"  
        android:pivotX="50%"  
        android:pivotY="50%" />  
</set>  

?

?其中:repeatCount = -1 ?表示无限循环的意思

? ? ? ? ? ? privotX="50%" ? ? ?表示旋转中心的X轴为相对于自身的50%,50%p 表示相对于屏幕X轴的50%

? ? ? ? ? ? privotY="50%" ? ? ?表示旋转中心的Y轴相对于自身的50%,50%p 表示相对于屏幕Y轴的50%

? ? ? ? ? ? duration="5000" ? 表示动画的时间为5000毫秒

?

3 activity中的代码

package com.example.rotateanimate;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends ActionBarActivity {
	private ImageView ivShape;
	private Button btnBegin;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		ivShape = (ImageView)findViewById(R.id.iv_sharp);
		btnBegin = (Button)findViewById(R.id.btn_start);
		final Animation animation = AnimationUtils.loadAnimation(this, R.anim.image_rotate_animate); 
		animation.setInterpolator(new LinearInterpolator());
		btnBegin.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				 ivShape.startAnimation(animation);
			}
		});
		
	}
}

?

? ? 需要注意的是:

? ? 在xml配置中不能设置旋转的速度,一定要在代码中加上红色的打断代码这段代码才能实现匀速旋转,否则会出现旋转一周后,停顿的情况。

?

图片无限旋转动画

原文:http://1029457926.iteye.com/blog/2193330

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!