这是我的情况。我有一个一个图像视图作为背景和第二个图像视图放在其顶部。在被用作背景的ImageView中,它旋转,因此我希望它的ImageView Ontop遵循完成的旋转翻译。我该怎么做?从本质上讲,我想要的是锚定第二个ImageView在旋转另一个ImageView时要遵循。这是我到目前为止的代码:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:clipChildren="false"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="65dp"
android:layout_marginTop="-20dp"
android:id="@+id/unit"
android:src="@drawable/unit"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:id="@+id/button"
android:src="@drawable/button"
/>
/>
private void rotate(int rotation) {
button.setTranslationX(1);
button.setTranslationY(-1);
if(rotation > 35) {
rotation = 35;
}
if(rotation < 0) {
rotation = 0;
}
Matrix matrix = new Matrix();
unit.setScaleType(ImageView.ScaleType.MATRIX);
matrix.postRotate(rotation,
unit.getDrawable().getBounds().width(), unit.getDrawable().getBounds().height());
unit.setImageMatrix(matrix);
}
您是否尝试过旋转相对布局?