Android 当只有文本_1获得数字时,当其他编辑文本为空时,如何使用相同按钮旋转唯一的红色箭头?

Android 当只有文本_1获得数字时,当其他编辑文本为空时,如何使用相同按钮旋转唯一的红色箭头?,android,image,rotation,Android,Image,Rotation,截图: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); redarrow = (ImageView) findViewById(R.id.red); greenarrow = (ImageView) findViewById(R.id.green);

截图:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    redarrow = (ImageView) findViewById(R.id.red);
    greenarrow = (ImageView) findViewById(R.id.green);
    yelowarrow = (ImageView) findViewById(R.id.yelow);

    text_1 = (EditText) findViewById(R.id.text_1);
    text_2 = (EditText) findViewById(R.id.text_2);
    text_3 = (EditText) findViewById(R.id.text_3);

    button_rotate = (Button) findViewById(R.id.button_rotate);


    button_rotate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            float text1 = Float.parseFloat(text_1.getText().toString());
            float text2 = Float.parseFloat(text_2.getText().toString());
            float text3 = Float.parseFloat(text_3.getText().toString());

            red.setRotation(text1);
            green.setRotation(text2);
            yelow.setRotation(text3);
        }
    });
}

更新:


上面的几行从箭头开始旋转动画。它基本上将箭头旋转180度。动画结束时,箭头将停留在那里。从而解决了问题。您可以将上面几行放在单击式侦听器中。

您能解释一下您的代码的作用以及如何应用它来解决问题中描述的问题吗?我有三个箭头图像“红色;绿色和黄色”。当我编辑文本中的数字时,我需要逐个旋转红色、绿色或黄色箭头,同时文本2和文本3是空的,它向我显示了错误,有一个图像link@GelaLataria你能附上一个stacktrace吗?
  private ObjectAnimator rotatingObjectAnimator;

  rotatingObjectAnimator = ObjectAnimator.ofFloat(red, "rotation", 0f, 180f);
  rotatingObjectAnimator.setDuration(1000);
  rotatingObjectAnimator.setInterpolator(new LinearInterpolator());
  rotatingObjectAnimator.start();