3

私はAndroidが初めてで、少し問題があります。RotateAnimation の次のコードを見つけました。

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 ファイル内にあるこの 2 つの値の変数を作成するにはどうすればよいですか?

    android:fromDegrees="0"
    android:toDegrees="360"
4

5 に答える 5

3

RotateAnimation クラス リファレンス (http://developer.android.com/reference/android/view/animation/RotateAnimation.html) によると、このクラスは fromDegrees と toDegrees のセッター メソッドを提供しません。したがって、これらの値をコードで設定する必要がある場合は、コードで RotateAnimation オブジェクトを作成し、fromDegrees 値と toDegrees 値をコンストラクターに渡す必要があります。

RotateAnimation rotateAnimation = new RotateAnimation(fromDegrees, toDegrees);
于 2012-10-05T08:16:42.563 に答える
0

次のコードを試してみてください。

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

メインコード:

  Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation);
    myView.startAnimation(rotation);
于 2012-10-05T07:55:20.820 に答える
0

別のものを試してください:

     Matrix matrix=new Matrix();
 imageView.setScaleType(ScaleType.MATRIX);   //required
 matrix.postRotate((float) angle, pivX, pivY);
 imagView.setImageMatrix(matrix);
于 2012-10-05T07:56:11.303 に答える
0
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromDegrees="0"
        android:toDegrees="360"
        android:duration="0"

        >
  <shape 
    android:shape="ring"
    android:innerRadiusRatio="2"
    android:thicknessRatio="10"
    android:useLevel="false">
    <shape
      android:width="76dip"
      android:height="76dip"/>
    <gradient android:type="sweep"
              android:useLevel="false"
              android:startColor="#F57847"
              android:endColor="#E67E55"
              android:angle="0"/>    
  </shape>



</rotate>**strong text**
于 2015-11-14T12:20:38.957 に答える