我在BottomNavigationView
我的项目中添加了一个动画,我想向其中一个菜单项添加动画。这个动画是一个AnimationDrawable
,基本上是一系列图像。我已经完成了以下操作,但没有成功,我知道如何实现这一点,或者尝试替代方法吗?
main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/lytMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/lytContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/nav"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentBottom="true"
android:background="@color/white"
app:menu="@menu/menu" />
</RelativeLayout>
菜单.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menShow"
android:enabled="true"
android:icon="@drawable/headphones"
android:title="@string/menu_listen"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menSearch"
android:enabled="true"
android:icon="@drawable/search"
android:title="@string/menu_search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menPlay"
android:enabled="true"
android:icon="@drawable/play_anim"
android:title="@string/menu_play"
app:showAsAction="ifRoom" />
</menu>
play_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/play_anim"
android:oneshot="false">
<item
android:drawable="@drawable/vis_f1"
android:duration="100" />
<item
android:drawable="@drawable/vis_f2"
android:duration="100" />
<item
android:drawable="@drawable/vis_f3"
android:duration="100" />
<item
android:drawable="@drawable/vis_f4"
android:duration="100" />
<item
android:drawable="@drawable/vis_f5"
android:duration="100" />
<item
android:drawable="@drawable/vis_f6"
android:duration="100" />
<item
android:drawable="@drawable/vis_f7"
android:duration="100" />
</animation-list>
MainActivity.java:
BottomNavigationView bottomView = (BottomNavigationView) findViewById(R.id.nav);
MenuItem menuItem = (MenuItem) bottomView.findViewById(R.id.menPlay);
AnimationDrawable animation = (AnimationDrawable)menuItem.getIcon();
animation.start();
到目前为止的结果是带有 3 个静态图像的菜单,我只想为其中一个设置动画。
任何帮助将不胜感激,在此先感谢