Reputation: 33
I have an two images in a relative layout. Image 2 is placed inside image 1. I want both images to rotate. Image one rotates perfectly but image 2 changes its position on rotation. Image 2 does not rotate around its original center.
java code
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 code
<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>
Upvotes: 2
Views: 1188
Reputation: 1015
i just made demo for rotation
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 button Click and wrote some code for rotation like
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);
}
});
Upvotes: 1