ImageView会在旋转时更改位置

时间:2015-03-27 11:43:27

标签: android rotation

我有两张相对布局的图片。图像2放置在图像1内。我希望两个图像都旋转。图像1完美旋转但图像2在旋转时改变其位置。图像2不会围绕其原始中心旋转。

java代码

 ImageView playcircle = (ImageView) findViewById(R.id.playcircle);
ImageView animationcircle =(ImageView)findViewById(R.id.animationcircle);
Animation a = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.linear_interpolator);
playcircle.startAnimation(a); 
animationcircle.startAnimation(a) ;

XML代码

<RelativeLayout..................>

    <ImageView
      android:id="@+id/playcircle"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/mainmenu_play_circle" />

        <ImageView
             android:id="@+id/animationcircle"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"

            android:layout_margin="60dp"
            android:src="@drawable/mainmenu_animation" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

我刚做了旋转演示

<强> activty_main.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/iv1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_delete_icon" />

    <ImageView
        android:id="@+id/iv2"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:padding="60dp"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>

Bind按钮单击并编写一些代码以便旋转,如

btnRotate.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360,
                        Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 0.5f);
                rotateAnimation1.setInterpolator(new LinearInterpolator());
                rotateAnimation1.setDuration(2000);
                rotateAnimation1.setRepeatCount(0);
                iv1.startAnimation(rotateAnimation1);
                iv2.startAnimation(rotateAnimation1);
            }
        });