我想在导航视图中的图片视图中应用动画。
我看到它在其他一些应用中运行良好。我尝试使用以下代码,但它不适用于我。
drawer_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_logout"
android:icon="@drawable/ic_logout"
android:title="@string/nav_menu_logout" />
</group>
<group
android:id="@+id/menu_sync"
android:checkableBehavior="single">
<item
android:id="@+id/nav_sync_now"
android:title="@string/string_menu_sync_now"
app:actionLayout="@layout/layout_menu_sync_now"
app:showAsAction="always" />
</group>
</menu>
NavigationActivity.java
runOnUiThread(new Runnable() {
@Override
public void run() {
MenuItem menuItemSync = navigationBinding.navView.getMenu().findItem(R.id.nav_sync_now);
menuItemSync.setEnabled(false);
menuItemSync.setTitle(R.string.string_menu_syncing);
mImageViewSyncing = (AppCompatImageView) menuItemSync.getActionView().findViewById(R.id.nav_sync_now_image_view);
mImageViewSyncing.setColorFilter(ContextCompat.getColor(mContext, R.color.colorAccent));
/* Create Animation */
Animation mRotateAnimation = AnimationUtils.loadAnimation(mContext, R.anim.button_rotate);
/* start Animation */
mImageViewSyncing.startAnimation(mRotateAnimation);
}
});
button_rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<rotate
android:duration="2500"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="0"
android:fromDegrees="360"/>
</set>
layout_menu_sync_now.xml
<android.support.v7.widget.AppCompatImageView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_sync_now_image_view"
android:layout_width="24dp"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_gravity="end|center_vertical"
app:srcCompat="@drawable/ic_sync_black" />
有什么建议吗?
提前致谢。