图像旋转Android

时间:2014-04-23 18:58:19

标签: android rotation imageview

我正在开发android。我想创建一个旋转图像并选择它上面的部分。例如,如果图像是人头,那么在其旋转时,可以选择耳朵。现在我做了图像部分选择,但我不知道如何旋转它?有人能告诉我一个简单的方法吗?

2 个答案:

答案 0 :(得分:0)

您应该使用http://developer.android.com/reference/android/view/animation/RotateAnimation.html类制作动画并为视图设置动画

答案 1 :(得分:0)

你有2种旋转图像的方法,我把简单的用xml。

首先在内部目录res中创建一个名为anim

的目录 在目录anim

使用以下代码创建一个文件xml:

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

此代码是使图像旋转的指令。

最后,您的主要活动必须如此:

public class MainActivity extends Activity implements OnClickListener{
    ImageView imagen; //declare the image will use
    Button boton; // this button will activie de rotation
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imagen = (ImageView) findViewById(R.id.iv);
        boton = (Button)findViewById(R.id.bt);

        boton.setOnClickListener(this); 

    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.bt:
            Animation rotacion; // declare an animation
            rotacion  = AnimationUtils.loadAnimation(this,R.anim.rotar);

            rotacion.reset();
            imagen.startAnimation(rotacion);

            break;

        default:
            break;
        }

    }