Android 动画旋转 [英] Android Animate Rotate

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

问题描述

我对Android代码进行了一些挖掘,并在不确定的进度条中看到了使用.在尝试使用此标签创建我自己的 drawable 后:

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" />

出现错误:在包 'android' 中找不到属性 '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?

我的任务是替换系统默认的不确定进度条.我想用尽可能少的代码来完成(如果可能,只更改几个属性).使用 ProgressBar 视图,设置:

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"

并将@drawable/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/anim/clock_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天全站免登陆