将标题倾斜到任意角度

时间:2014-01-28 10:39:36

标签: android sensor

我试图以任何角度倾斜图像,但我无法这样做 在这里,我提供了我已经处理过的代码。

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

        float x = event.values[0];
        float y = event.values[1];
        float z = event.values[2];
        text1.setText("X: " + x);
        text2.setText("Y: " + y);
        text3.setText("Z: " + z);
        if (Math.abs(x) > Math.abs(y)) {
            if (x < 0) {
                //Matrix matrix = new Matrix();
                //iv.setScaleType(ScaleType.MATRIX); // required
                //matrix.postRotate((float) 25, x, y);
                //iv.setImageMatrix(matrix);
             iv.setImageResource(R.drawable.images);
            }
            if (x > 0) {

                 iv.setImageResource(R.drawable.images);
            }
        } else {
            if (y < 0) {

                 iv.setImageResource(R.drawable.images);
            }
            if (y > 0) {

                 iv.setImageResource(R.drawable.images);
            }
        }
        if (x > (-2) && x < (2) && y > (-2) && y < (2)) {

             iv.setImageResource(R.drawable.images);
        }   }}

。任何人都可以建议如何实现

2 个答案:

答案 0 :(得分:3)

你应该尝试以下内容来旋转你的imageView:

Matrix matrix=new Matrix();
imageView.setScaleType(ScaleType.MATRIX);   //required
matrix.postRotate((float) angle, pivX, pivY);
imageView.setImageMatrix(matrix);

请给我一些反馈

希望有所帮助。

答案 1 :(得分:2)

它非常简单。你不需要编写这么多代码。使用yourImageView.setRotation(Rotation_angle)按照Rotation_angle的值将图像倾斜一定的度数。

您可以询问是否有任何进一步的疑问。快乐编码:)

相关问题