Ahsan
Ahsan

Reputation: 2982

how to rotate a circular image button on its own axis in android app?

I have the following animation code :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate

android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="100"
android:duration="1000" />

</set>

//imageButton layout code

<ImageButton
android:id="@+id/anime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/start"
android:layout_centerHorizontal="true"
android:paddingLeft="10dip"
android:paddingTop="150dip"
android:paddingBottom="10dip"
android:paddingRight="10dip"
android:background="@null"
>
</ImageButton>

However, my circular image button is not rotating on its own axis. Rather, its following a circular path. Can anyone kindly help me out fix this animation ?

Thanks.

Upvotes: 2

Views: 2881

Answers (2)

aromero
aromero

Reputation: 25761

The pivot calculation in the animation is taking into account the padding of the ImageView. Since the padding is irregular (the top padding is different from the rest of the sides) the pivot of the animation is not aligned with the real center of your image.

Upvotes: 2

Ahsan
Ahsan

Reputation: 2982

the padding for the imagebutton should be uniform.

Upvotes: 0

Related Questions