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

わかった

public void 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 に答える