0

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:background="@android:color/transparent"
              android:id="@+id/globeViewStreamInfoPanel"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

    <ImageView android:id="@+id/streamIndicator"
               android:src="@drawable/nv_tidestreamindicator"
               android:scaleType="matrix"
               android:layout_alignParentTop="true"
               android:layout_alignParentLeft="true"
               android:layout_margin="10dp"
               android:maxHeight="40dp"
               android:maxWidth="40dp"
               android:layout_width="40dp"
               android:layout_height="40dp"/>

代码(streamIndicatorImageView):

streamIndicatorMatrix.reset();
streamIndicatorMatrix.setScale(size,size);

// rotate indicator in the direction of the flow
streamIndicatorMatrix.setRotate((float)(stream.currentStream.direction));

streamIndicator.setImageMatrix(streamIndicatorMatrix);

当我旋转或缩放或两者兼而有之时,ImageView 在布局中移动。

奇怪的是,当我在setImagematrix检查streamIndicator, mTop, mLeft,之后断线时mWidthmHeight一切看起来都是正确的。 size我的旋转角度始终是合法的、合理的值。

我只知道这是愚蠢的,我错过了什么?

谢谢!

[编辑]

这是一张图片,我添加了红色箭头以指向错误的 ImageView:

在此处输入图像描述

4

1 回答 1

1

Matrix.setRotate默认使用(0, 0)轴心点。这就是您的图像在布局中移动的原因。该方法有一个重载版本Matrix.setRotate,可让您指定枢轴点。

final float density = getResources().getDisplayMetrics().density;
final int center = Math.round(20 * density);

streamIndicatorMatrix.setScale(size,size, center, center);
streamIndicatorMatrix.setRotate((float)(stream.currentStream.direction), center, center);
于 2013-03-17T12:16:36.163 回答