-2
Pouvons-nous faire pivoter l'imageview ayant la source (image attachée) avec le doigt le long de son centre dans android? Faire pivoter Imageview like steering?
Pouvons-nous faire pivoter l'imageview ayant la source (image attachée) avec le doigt le long de son centre dans android? Faire pivoter Imageview like steering?
public class MainActivity extends Activity implements OnTouchListener{
private ImageView wheel;
private double mCurrAngle = 0;
private double mPrevAngle = 0;
ImageView bask;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wheel=(ImageView)findViewById(R.id.imageView1);
wheel.setOnTouchListener(this);
}
@Override
public boolean onTouch(final View v, MotionEvent event) {
final float xc = wheel.getWidth()/2;
final float yc = wheel.getHeight()/2;
final float x = event.getX();
final float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
wheel.clearAnimation();
mCurrAngle = Math.toDegrees(Math.atan2(x - xc, yc - y));
break;
}
case MotionEvent.ACTION_MOVE: {
mPrevAngle = mCurrAngle;
mCurrAngle = Math.toDegrees(Math.atan2(x - xc, yc - y));
animate(mPrevAngle, mCurrAngle, 0);
System.out.println(mCurrAngle);
break;
}
case MotionEvent.ACTION_UP : {
mPrevAngle = mCurrAngle = 0;
break;
}
}
return true;
}
private void animate(double fromDegrees, double toDegrees, long durationMillis) {
final RotateAnimation rotate = new RotateAnimation((float) fromDegrees, (float) toDegrees,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(durationMillis);
rotate.setFillEnabled(true);
rotate.setFillAfter(true);
wheel.startAnimation(rotate);
System.out.println(mCurrAngle);
}
}
Référence andygeeks.blogspot.in. – EED
Commander -> https://code.tutsplus.com/tutorials/android-sdk-creating-a-rotating-dialer--mobile-8868 – AndiGeeky
Cochez cette case URL comme référence: - http: // andygeeks.blogspot.in/2014/05/how-to-animate-image-to-rotate-with.html – Bhavnik
Merci d'avoir répondu AndiGeeky. Mais ce n'est pas roatating autour de son centre.S'il vous plaît donner vos suggestions précieuses pour remédier à ce problème – EED