如何在曲面视图上旋转叠加图像后设置高度和宽度

时间:2018-02-24 10:28:05

标签: android android-layout

我想在ImageView上设置动态图像,但要覆盖表面视图并执行一些基本的图像编辑操作,如缩放,旋转和变换。现在,当我在横向模式下旋转带有屏幕旋转的ImageView时,它需要纵向模式的高度和宽度。我以纵向模式锁定了我的活动。

landscape mode-- overlay image on surface view portrait mode image on surface view

final int ROTATION_O    = 0;
final int ROTATION_90   = 90;
final int ROTATION_180  = 180;
final int ROTATION_270  = 270;

private int rotation = 0;
public void onOrientationChanged(int orientation) {
    if( (orientation < 35 || orientation > 325) && rotation!= ROTATION_O){ // PORTRAIT
        rotation = ROTATION_O;
        imgView.setRotation(rotation);
    }
    else if( orientation > 145 && orientation < 215 && rotation!=ROTATION_180){ // REVERSE PORTRAIT
        rotation = ROTATION_180;
        imgView.setRotation(rotation);
    }
    else if(orientation > 55 && orientation < 125 && rotation!=ROTATION_270){ // REVERSE LANDSCAPE
        rotation = ROTATION_270;
        imgView.setRotation(rotation);
    }
    else if(orientation > 235 && orientation < 305 && rotation!=ROTATION_90){ //LANDSCAPE
        rotation = ROTATION_90;
        imgView.setRotation(rotation);
    }
}

1 个答案:

答案 0 :(得分:0)

这个图书馆可以帮助你

uCrop

我想如果屏幕操作更改可以解决您的问题,可能会获得高度和宽度

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
    Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}