Reputation: 1531
I have a class which extends Fragment, I want to make rotation of ImageView when onCreateView() called.
Here is my code:
rotator.xml - set animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate xmlns:android="”http://schemas.android.com/apk/res/android”"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:duration="1000"/>
</set>
Here I use my animation:
public class SearchFragment extends Fragment {
Context context;
private ImageView backButtonImage;
private Animation rotation;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = container.getContext();
View root = inflater.inflate(R.layout.search, container, false);
backButtonImage = (ImageView) root.findViewById(R.id.backButton);
rotation = AnimationUtils.loadAnimation(context, R.anim.rotator);
backButtonImage.startAnimation(rotation);
return root;
}
But, when I run my app the image doesn't rotate. What am I doing wrong ?
Upvotes: 2
Views: 2153
Reputation: 844
You have a problem in your rotator.xml:
<rotate xmlns:android="”http://schemas.android.com/apk/res/android”"
You have an extra set of quotes which are invalid in an xml, it should be like this:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
But you don't even need to specify the xmlns:android property since you already did it on your root element, so the whole file can be like this:
<?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="1"
android:duration="1000"/>
</set>
Upvotes: 4