2
其實我編程使用圖像旋轉的應用程序。但是當我旋轉圖像時,它不顯示任何東西。在Android中旋轉後未顯示ImageView
這是我的代碼:
XML文件:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rotate_test_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/android"
android:src="@drawable/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:scaleType="matrix"
android:adjustViewBounds="true"
android:contentDescription="@string/android_description" >
</ImageView>
</LinearLayout>
活動文件:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rotate_test_layout);
ImageView imageView = (ImageView)findViewById(R.id.android);
imageView.setScaleType(ScaleType.MATRIX);
Matrix matrix = new Matrix();
matrix.postRotate(90);
imageView.setImageMatrix(matrix);
}
這種方法會在大的位圖上導致OOM。有一篇文章討論這個解決方案的這個問題。 http://stackoverflow.com/a/10104318/2123400 但對我來說,這個解決方案不起作用,因爲你的答案告訴你爲什麼。我很困惑爲什麼很多人可以在不創建新位圖的情況下旋轉ImageView的圖像。 – Eftekhari 2016-05-30 15:22:35