【问题标题】:Rotating wheel in androidandroid中的旋转轮
【发布时间】:2015-05-02 16:02:27
【问题描述】:

我的图像视图由圆轮组成,如下图所示。我希望该轮应在用户按下开始按钮后立即开始旋转,并在用户按下停止按钮时停止旋转。是否可以通过编程方式进行?如果是,我怎么能这样做?

【问题讨论】:

标签: android rotation android-animation android-imageview


【解决方案1】:

创建一个名为顺时针旋转.xml的文件并放入/res/anim根据需要更改持续时间。

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

并在两个按钮中调用这两个函数

private void startAnimation(){
    Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.clockwise_rotation);
    mImageView.startAnimation(rotation);
}

private void stopAnimation(){
    mImageView.clearAnimation();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多