Android的动画旋转 [英] Android Animate Rotate

查看:878
本文介绍了Android的动画旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的Andr​​oid code一些挖掘,看见在不确定的进度栏的使用。试图创建自己绘制这个标签之后:

I did some digging in Android code, and saw the use of in the indeterminate progress bar. after trying to create my own drawable with this tag:

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner_pia"
    android:pivotX="50%"
    android:pivotY="50%"
    android:framesCount="12"
    android:frameDuration="100" />

我得到一个错误: 未找到属性frameDuration中包机器人资源标识符 - 这意味着,frameDuration是私有属性。 有没有办法使用这种动画,旋转功能?

I get an error: "No resource identifier found for attribute 'frameDuration' in package 'android'" - which means that frameDuration is a private attribute. Is there a way to use this "animate-rotate" feature?

我的任务是替换系统默认的不确定的进度栏。我想做到这一点用尽可能少code为可能的(只是改变一些属性如果可能的话)。 使用进度视图,设置:

My task is to replace the system's default indeterminate progress bar. I'd like to do it with as little code as possible (just change few attributes if possible). Using the ProgressBar view, setting:

android:indeterminateOnly="true"
android:indeterminateBehavior="cycle"
android:indeterminateDuration="3500"
android:indeterminateDrawable="@drawable/pia_sivuvator"

和点@绘制/ pia_sivuvator该对象会一直让我的任务,因为优雅的,因为他们来了,但我卡上的私有属性。

and point "@drawable/pia_sivuvator" to that object would've make my task as elegant as they come but I'm stuck on those private attributes.

帮助?

推荐答案

我遇到了完全一样的问题。您可以排除这些参数(framesCount和frameDuration),它可以为你工作。我尝试过不包括他们,它的动画不错,但宽度/高度我设置没有被尊重,所以我结束了创建一个简单的旋转动画和ImageView的将其应用到。这里的动画文件(RES /阿尼姆/ clockwise_rotation.xml):

I ran into the exact same issue. You can exclude those parameters (framesCount and frameDuration), and it may work for you. I tried just excluding them and it animated fine, but the width/height I was setting were not being respected, so I ended up creating a simple rotation animation and an ImageView to apply it to. Here's the animation file (res/anim/clockwise_rotation.xml):

<?xml version="1.0" encoding="utf-8"?>
<rotate
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:fromDegrees="0"
  android:interpolator="@android:anim/linear_interpolator"
  android:toDegrees="360"
  android:pivotX="50%"
  android:pivotY="50%"
  android:duration="1000"
  android:startOffset="0"
/>

然后你只需抬高你的动画,设置重复次数,并从视图

Then you just inflate your Animation, set repeat count, and start it from the View

Animation rotation = AnimationUtils.loadAnimation(this, R.anim.clockwise_rotation);
rotation.setRepeatCount(Animation.INFINITE);
myView.startAnimation(rotation);

这篇关于Android的动画旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆