1

我有一个图像视图,我需要在 android(纵向、横向、反向纵向和反向横向)中旋转(使用类似 IOS 的动画)方向更改的图像视图。

请指教

void rotateAndSet(int angle) {

    if (currentAngle != angle || currentImage != currentBaseImage) { // This
        // is
        // to
        // remove
        // unnecessary
        // drawing
        currentAngle = angle;
        currentImage = currentBaseImage;
        myImg = decodeBase64(currentBaseImage);

        matrix = new Matrix();
        matrix.postRotate(angle);
        Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(),
                myImg.getHeight(), matrix, true);
        RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        param.addRule(RelativeLayout.ALIGN_PARENT_TOP);

        /*RotateAnimation animation = new RotateAnimation(0, 90,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); 
        animation.setInterpolator(new LinearInterpolator()); 
        animation.setFillAfter(true); 
        animation.setDuration(800); 
        ivFullScreen.startAnimation(animation); */
        ivFullScreen.setLayoutParams(param);
        ivFullScreen.setImageBitmap(rotated);
    }

}

在此处输入图像描述

4

1 回答 1

0

我得到了它

公共无效 onSensorChanged(SensorEvent 事件){

    synchronized (this) {
        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            RotateAnimation animation = null;
            if (event.values[0] < 4 && event.values[0] > -4) {
                if (event.values[1] > 0 && orientation != ExifInterface.ORIENTATION_ROTATE_90) {
                    // UP
                    orientation = ExifInterface.ORIENTATION_ROTATE_90;
                    Log.i("testme","up");
                    animation = getRotateAnimation(0);
                    degrees = 0;
                } else if (event.values[1] < 0 && orientation != ExifInterface.ORIENTATION_ROTATE_270) {
                    // UP SIDE DOWN
                    Log.i("testme","up side down");
                    orientation = ExifInterface.ORIENTATION_ROTATE_270;
                    animation = getRotateAnimation(180);
                    degrees = 180;
                }
            } else if (event.values[1] < 4 && event.values[1] > -4) {
                if (event.values[0] > 0 && orientation != ExifInterface.ORIENTATION_NORMAL) {
                    // LEFT
                    Log.i("testme","left");
                    orientation = ExifInterface.ORIENTATION_NORMAL;
                    animation = getRotateAnimation(-270);
                    degrees =-270;
                } else if (event.values[0] < 0 && orientation != ExifInterface.ORIENTATION_ROTATE_180) {
                    // RIGHT
                    Log.i("testme","right");
                    orientation = ExifInterface.ORIENTATION_ROTATE_180;
                    animation = getRotateAnimation(270);
                    degrees = 270;
                }
            }
            if (animation != null) {
                ivFullScreen.startAnimation(animation);
            }
        }

    }

}
于 2014-08-06T06:15:16.443 回答