Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android rotate imageview动画问题_Android_Android Animation_Android Imageview - Fatal编程技术网

Android rotate imageview动画问题

Android rotate imageview动画问题,android,android-animation,android-imageview,Android,Android Animation,Android Imageview,我正在使用android旋转ImageView。当我运行Project时,onCreate()中的动画工作正常,但当我尝试单击按钮启动动画时,动画不工作 我怎样才能修好它 XML代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_paren

我正在使用android旋转ImageView。当我运行Project时,onCreate()中的动画工作正常,但当我尝试单击按钮启动动画时,动画不工作

我怎样才能修好它

XML代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/getAngle"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:inputType="number" />

<ImageView
    android:id="@+id/rotateImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@drawable/spinner_new" />

<Button
    android:id="@+id/startbutton"
    android:layout_width="200dp"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="Start" />

执行以下步骤,它肯定会工作 1) 为xml relativelayout(父布局)提供Id[我只提供了relative] 2) 执行以下代码:

 public class MainActivity extends Activity {

EditText getAngle;
ImageView rotateImage;
RelativeLayout relative;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


getAngle = (EditText) findViewById(R.id.getAngle);
rotateImage = (ImageView) findViewById(R.id.rotateImage);
  relative = (RelativeLayout)findViewById(R.id.relative);
Button startbutton = (Button) findViewById(R.id.startbutton);
startbutton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        String endPointString = getAngle.getText().toString();
        int endPointInt = Integer.parseInt(endPointString);

        Animation rotateanimation = new RotateAnimation(0, endPointInt,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        rotateanimation.setDuration(1000);
        rotateanimation.setRepeatCount(0);
        rotateanimation.setRepeatMode(Animation.REVERSE);
        rotateanimation.setFillAfter(true);
        rotateImage.setAnimation(rotateanimation);
        rotateanimation.start();
         relative.invalidate();

    }
});

}

}

请立即@user123456执行此操作
 public class MainActivity extends Activity {

EditText getAngle;
ImageView rotateImage;
RelativeLayout relative;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


getAngle = (EditText) findViewById(R.id.getAngle);
rotateImage = (ImageView) findViewById(R.id.rotateImage);
  relative = (RelativeLayout)findViewById(R.id.relative);
Button startbutton = (Button) findViewById(R.id.startbutton);
startbutton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        String endPointString = getAngle.getText().toString();
        int endPointInt = Integer.parseInt(endPointString);

        Animation rotateanimation = new RotateAnimation(0, endPointInt,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        rotateanimation.setDuration(1000);
        rotateanimation.setRepeatCount(0);
        rotateanimation.setRepeatMode(Animation.REVERSE);
        rotateanimation.setFillAfter(true);
        rotateImage.setAnimation(rotateanimation);
        rotateanimation.start();
         relative.invalidate();

    }
});

}

}