我使用Matrix.postRotate()
方法来旋转我的图像,但现在它不再自动缩放以适合父LinearLayout
。以下是相关代码…
private ImageView rotateimage(ImageView dotimage) {
Matrix matrix=new Matrix();
dotimage.setScaleType(ScaleType.MATRIX);
matrix.postRotate((float) 90, 374, 374);
dotimage.setImageMatrix(matrix);
return dotimage;}
,这是我的布局和ImageView
的xml…
<LinearLayout
android:id="@+id/LinearLayout2"
android:layout_width="550dp"
android:layout_height="550dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/dotdescription"
android:src="@drawable/dots1" />
</LinearLayout>
我已经使用Matrix.postScale()
方法固定了缩放,但我真的很好奇为什么自动缩放不再工作。
提前感谢!
自动缩放不起作用,因为您已经显式地将其更改为ScaleType.MATRIX
——这意味着所有的转换都应该由您的矩阵处理。