ImageView becomes blank on Screen orientation change

不打扰是莪最后的温柔 提交于 2019-12-31 03:38:26

问题


I am using the below line to set my ImageView.

    Bitmap bm = Media.getBitmap(getContentResolver(), capturedImage);
                    Bitmap bm1=Bitmap.createScaledBitmap(bm, 300, 300,true);
                    pic.setImageBitmap(bm1);

But when I rotate my mobile, the imageView becomes blank. Can anyone help me. Any help is appreciated.


回答1:


Proper way to it is to save the bitmap in onRetainNonConfigurationInstance()

Here is an example: http://developer.android.com/guide/topics/resources/runtime-changes.html




回答2:


Try adding android:configChanges="orientation|keyboardHidden" to your Activity tag in your AndroidManifest. Take a look here for more details.




回答3:


You should save capturedImage in your onSaveInstanceState method, and then check in your onRestoreInstanceState method to see if you saved it and then re-execute the code you have above. See the answer of Saving Android Activity state using Save Instance State for an excellent example of how this would work.



来源:https://stackoverflow.com/questions/6111039/imageview-becomes-blank-on-screen-orientation-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!