[英]How to set height and width after rotate of overlay image on surface view
我想在ImageView上設置動態圖像,但覆蓋表面視圖,並執行一些基本的圖像編輯操作,例如縮放,旋轉和變換。 現在,當我在橫向模式下通過屏幕旋轉來旋轉ImageView時,它將采用縱向模式的高度和寬度。 我將活動鎖定為縱向模式。
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);
}
}
該庫可以為您提供幫助
我想也許如果在更改屏幕操作時獲得高度和寬度可以解決問題
@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();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.