gal gal - 4 months ago 8
Android Question

Position during Animation rotate android

I'm doing an application game. I have a framelayout rotating by Animation Rotate.
The framelayout got some Imageviews within. I'm interested to know what the position of the Imgaevies in every moment during the rotartion.
Right now it gives me back the initial position in the image before the rotate happened.

Thank you in advance for your help.

Setup and use of the Animation:

private Animation animRotate;
this.animRotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
FrameLayout fl = (FrameLayout)this.findViewById(R.id.imageviewlayout);
fl.startAnimation(animRotate);
ImageView mimage=(ImageView)this.findViewById(R.id.image);
mimage.setOnClickListener(this);


This is the rotate.xml

<?xml version="1.0" encoding="utf-8"?>
<set android:interpolator="@android:anim/linear_interpolator"
xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:toDegrees="360"
android:startOffset="0"
android:repeatMode="restart"
android:repeatCount="800"
android:pivotY="50%"
android:pivotX="50%"
android:fromDegrees="0"
android:duration="4500"/>
</set>


The onclick method:

@Override
public void onClick(View v) {
float[] locations ={0,0};
locations[0] = v.getX();
locations[1] = v.getY();
Toast.makeText(getApplicationContext(),"x= "+locations[0]+"y = "+locations[1] + "pressed "+!!!!",Toast.LENGTH_LONG).show();
v.setVisibility(View.GONE);
}

gal gal
Answer

That helped me!

FrameLayout fl = (FrameLayout)this.findViewById(R.id.imageviewlayout);      
ObjectAnimator animation = ObjectAnimator.ofFloat(fl, "rotation", 0,360); 
animation.setDuration(4000); 
animation.setRepeatCount(ObjectAnimator.INFINITE); 
animation.setInterpolator(new AccelerateDecelerateInterpolator()); 
animation.start();