0
我想在更改屏幕方向时更改图像大小。我试图使用下面的代码,但它不起作用。调整位图图像大小?
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
myImage = Bitmap.createBitmap(BitmapFactory
.decodeResource(this.getResources(), R.drawable.pic));
Display d = ((WindowManager)getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
int ScreenHeight = d.getHeight();
int ScreenWidth = d.getWidth();
Bitmap ScaledImage = Bitmap.createScaledBitmap(myImage , ScreenWidth, ScreenHeight,
true);
imageview = (ImageView)findViewById(R.id.imageView2);
imageview.setImageBitmap(ScaledImage);
}
}
嗨,阿尔斯兰感谢您的帮助在旋转或重新大小的图像的代码,其实我已经加入我的menifest这条线,但它不工作。在纵向模式下工作,问题仅在横向模式下。任何其他建议。 – KKC
请检查我的新答案。 – Arslan
谢谢,阿尔斯兰其工作。非常感谢你。 – KKC