更改传感器值的颜色

时间:2018-12-02 13:38:58

标签: java android

我是Java的新手,我需要帮助。

我正在开发量角器应用程序。 如何更改输出值的颜色? 如果该值小于90°,​​则文本应为红色等。

预先感谢

这是我的代码:

  if (mags != null && accels != null) {
                gravity = new float[9];
                magnetic = new float[9];
                SensorManager.getRotationMatrix(gravity, magnetic, accels, mags);
                float[] outGravity = new float[9];
                SensorManager.remapCoordinateSystem(gravity, SensorManager.AXIS_X, SensorManager.AXIS_Z, outGravity);
                SensorManager.getOrientation(outGravity, values);

                roll = values[2];
                mags = null;
                accels = null;
                double degree = Math.toDegrees(roll);
                double mapped = 90 - Math.min(90, degree);
                double newvalue = mapped - 180;


                    zValue.setText(Math.round(mapped) + "°" );

               if (mapped > 90){

                   newvalue *= -1;
                   zValue.setText(Math.round(newvalue) + "°");


               }

            }

        }
        }

        ;
    }

0 个答案:

没有答案