Подтвердить что ты не робот

Как вращать значок андроида в его центральной точке?

Я написал следующее, чтобы развернуть значок в центре экрана, и вместо этого он вращается вокруг верхнего левого угла (то есть, начало x = 0, y = 0 ImageView). Должно быть просто установить некоторые атрибуты ImageView или RotateAnimation, но я не могу понять это.

public class IconPromoActivity extends Activity {
    private static final float ROTATE_FROM = 0.0f;
    private static final float ROTATE_TO = -10.0f * 360.0f;// 3.141592654f * 32.0f;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageView favicon = (ImageView) findViewById(R.id.favicon);

        RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO);
        r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, 0, 0, 40, 0);
        r.setDuration((long) 2*1500);
        r.setRepeatCount(0);
        favicon.startAnimation(r);
    }
}
4b9b3361

Ответ 1

Try: r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

Ответ 2

Это работает для меня:

img = (ImageView)findViewById(R.id.ImageView01);
RotateAnimation rotateAnimation = new RotateAnimation(30, 90,
    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);