http://www.tuicool.com/articles/eMnEJnN
http://blog.youkuaiyun.com/heaimnmn/article/details/20542397
因为最近工作较忙的原因,可能更新较慢,而且内容越来越细,从一个完整的app到一个
简单的功能,甚至到UI设计,今天介绍的就是一个常见的UI设计,先上图:
别看只是个简单的UI,只有几行代码,当时我把这个demo卖给客户赚了300RMB,就几
行代码, 其实这个代码的核心在于,自定义 animation的rotate动画,
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <rotate
- android:interpolator="@android:anim/accelerate_decelerate_interpolator"
- android: fromDegrees ="0"
- android:repeatCount="infinite"
- android:pivotX="50%"
- android:pivotY="50%"
- android:duration="3000"
- ndroid:toDegrees="360.0"
- />
- <!-- rotate 旋转动画效果
- 属性:interpolator 指定一个动画的插入器
- 在我试验过程中,使用android.res.anim中的资源时候发现
- 有三种动画插入器:
- accelerate_decelerate_interpolator 加速-减速 动画插入器
- accelerate_interpolator 加速-动画插入器
- decelerate_interpolator 减速- 动画插入器
- 其他的属于特定的动画效果
- 浮点数型值:
- fromDegrees 属性为动画起始时物件的角度
- toDegrees 属性为动画结束时物件旋转的角度 可以大于360度
- 说明:
- 当角度为负数——表示逆时针旋转
- 当角度为正数——表示顺时针旋转
- (负数from——to正数:顺时针旋转)
- (负数from——to负数:逆时针旋转)
- (正数from——to正数:顺时针旋转)
- (正数from——to负数:逆时针旋转)
- pivotX 属性为动画相对于物件的X坐标的开始位置
- pivotY 属性为动画相对于物件的Y坐标的开始位置
- 说明: 以上两个属性值 从0%-100%中取值
- 50%为物件的X或Y方向坐标上的中点位置
- 长整型值:
- duration 属性为动画持续时间
- 说明: 时间以毫秒为单位
- -->
然后就是调用这个这个自定义的rotate
RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(context, R.anim.refresh); // 加载XML文件中定义的动画
并且通过自定义dialog完整显示出来,完整代码如下:
public MyProgressDialog(Context context, int theme) { super(context, theme); this.context = context; View view = LayoutInflater.from(context).inflate(R.layout.load, null); // 加载自己定义的布局 ImageView img_loading = (ImageView) view.findViewById(R.id.img_load); RelativeLayout img_close = (RelativeLayout) view.findViewById(R.id.img_cancel); RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(context, R.anim.refresh); // 加载XML文件中定义的动画 img_loading.setAnimation(rotateAnimation);// 开始动画 setContentView(view);// 为Dialoge设置自己定义的布局 // 为close的那个文件添加事件 img_close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dismiss(); } }); }