繁体   English   中英

Android Imageview彼此旋转

[英]Android Imageview ontop of each other with rotation

这是我的情况。 我有一个imageview被放置为背景,第二个imageview被放置在其顶部。 在用作背景的imageview中,它旋转,因此我希望它上面的imageview跟随已完成的旋转平移。 我该怎么做? 本质上,我想要的是在旋转另一个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);
}

您是否尝试过旋转相对布局?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM