我是android新手,有点小问题。
我找到了旋转成像的代码:
存储RotateAnimation所有数据的XML文件:

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

Java文件:
package com.example.helloword;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class Rotation_test extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rotation_test);
//        getActionBar().setDisplayHomeAsUpEnabled(true);


        Button buttonRotateCenter = (Button) findViewById(R.id.rotatecenter);
        final ImageView floatingImage = (ImageView) findViewById(R.id.floatingimage);


        final Animation animationRotateCenter = AnimationUtils.loadAnimation(
                this, R.anim.rotate_center);
        buttonRotateCenter.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                floatingImage.startAnimation(animationRotateCenter);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_rotation_test, menu);
        return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

如何创建XML文件中这两个值的变量?
    android:fromDegrees="0"
    android:toDegrees="360"

最佳答案

根据RotateAnimation类引用(http://developer.android.com/reference/android/view/animation/rotateAnimation.html),该类不提供FromDegrees和ToDegrees的setter方法。因此,如果需要在代码中设置这些值,则必须在代码中创建rotateAnimation对象,并将fromDegrees和toDegrees值传递到构造函数中。

RotateAnimation rotateAnimation = new RotateAnimation(fromDegrees, toDegrees);

10-06 06:32