0

我正在尝试在 RemoteViews 中旋转位图。但是,当我使用任何一个 Matrix.setRotate 方法或任何一个 Matrix.postRotate 方法时,位图都会变得奇怪。这是我用来完成任务的代码。

Bitmap bMap = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow);
Matrix m = new Matrix();
m.setRotate((float) 0, bMap.getWidth()/2, bMap.getHeight()/2);
bMap = Bitmap.createBitmap(bMap,0,0, bMap.getWidth(),bMap.getHeight(),m, true);

RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.speedometer);
remoteView.setImageViewBitmap(R.id.speedoNeedle, bMap);

这是原始布局文件xml:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="136px"
android:layout_height="136px"
 >

<ImageView
        android:layout_width="136px"
        android:layout_height="136px"
        android:src="@drawable/dial"
        />
<ImageView
        android:id="@+id/speedoNeedle"
        android:layout_width="9px"
        android:layout_height="78px"
        android:layout_marginLeft="63px"
        android:layout_marginTop="27px"
        android:rotation="-138"
        android:src="@drawable/arrow" />
</RelativeLayout>

如果我将旋转值设置为零或注释掉m.setRotate((float) 0, bMap.getWidth()/2, bMap.getHeight()/2)位图正确显示。

在此处输入图像描述

如果我将旋转值设置为 138,我会得到:你几乎看不到针。

在此处输入图像描述

这是 184 的值的屏幕截图:

在此处输入图像描述

在最大值 276 时甚至看不到针。

我究竟做错了什么?我该如何解决?

提前致谢。

4

1 回答 1

1

好吧,从第一个角度来看,你已经将 speedoNeedle ImageView 的宽度设置为 9px,这对于箭头位图的整个角度范围似乎不够......这不是问题吗?据我了解,您正在围绕其中心旋转整个箭头位图,因此旋转位图的尺寸会有所不同......首先,我会尝试将 speedoNeedle ImageView 的宽度和高度设置为相同的号码。

于 2013-07-18T15:53:21.390 回答