【问题标题】:Need help on rotating image view with animation on orientation change (4 side rotation) in android需要帮助旋转图像视图并在 android 中使用方向更改(4 侧旋转)动画
【发布时间】:2014-08-06 14:15:16
【问题描述】:

我有一个图像视图,我需要在 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);
    }

}

【问题讨论】:

    标签: screen-orientation android-orientation rotateanimation scaleanimation


    【解决方案1】:

    我明白了

    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);
                }
            }
    
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多