底部导航视图中可绘制的动画矢量

时间:2019-07-11 12:16:25

标签: android android-animation bottomnavigationview

如何在底部导航视图中为动画的矢量可绘制xml设置动画?有任何指导方针或图书馆可以这样做吗?我已经搜索过此内容,但没有与此相关的资源。

我有这个动画矢量绘图

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
tools:targetApi="lollipop">
<aapt:attr name="android:drawable">
    <vector
        android:name="vector"
        android:width="788dp"
        android:height="788dp"
        android:viewportWidth="788"
        android:viewportHeight="788">
        <group
            android:name="group"
            android:rotation="1">
            <path
                android:name="bell"
                android:pathData="M 782.7 454 L 729.9 416.5 C 705.5 399.2 686.2 375.6 674.2 348.2 L 654.6 303.6 C 629.9 247.3 571.5 216.2 513.4 223.4 L 499.4 191.5 C 490.8 171.9 467.9 162.9 448.2 171.5 C 428.6 180.1 419.6 203 428.2 222.7 L 442.2 254.6 C 397.6 292.5 380.9 356.5 405.6 412.8 L 425.2 457.4 C 437.2 484.8 441.5 514.9 437.8 544.6 L 429.6 608.9 C 429.2 612.4 430.6 615.8 433.4 617.9 C 436.2 620 439.9 620.4 443.1 619 L 780.9 470.8 C 784.1 469.4 786.3 466.4 786.7 462.9 C 787.1 459.4 785.5 456 782.7 454 Z M 563.8 587.2 C 583 603.7 610.7 609.1 635.4 598.2 C 660.1 587.3 675 563.4 675.8 538.1 L 563.8 587.2 Z"
                android:fillColor="#000"
                android:strokeWidth="1"/>
        </group>
    </vector>
</aapt:attr>
<target android:name="group">
    <aapt:attr name="android:animation">
        <set>
            <objectAnimator
                android:propertyName="rotation"
                android:duration="100"
                android:valueFrom="0"
                android:valueTo="50"
                android:valueType="floatType"
                android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
            <objectAnimator
                android:propertyName="pivotX"
                android:duration="100"
                android:valueFrom="500"
                android:valueTo="500"
                android:valueType="floatType"
                android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
            <objectAnimator
                android:propertyName="pivotY"
                android:duration="100"
                android:valueFrom="128"
                android:valueTo="128"
                android:valueType="floatType"
                android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
            <objectAnimator
                android:propertyName="rotation"
                android:startOffset="100"
                android:duration="100"
                android:valueFrom="50"
                android:valueTo="1"
                android:valueType="floatType"
                android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
            <objectAnimator
                android:propertyName="pivotX"
                android:startOffset="100"
                android:duration="100"
                android:valueFrom="500"
                android:valueTo="500"
                android:valueType="floatType"
                android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
            <objectAnimator
                android:propertyName="pivotY"
                android:startOffset="100"
                android:duration="100"
                android:valueFrom="128"
                android:valueTo="128"
                android:valueType="floatType"
                android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
        </set>
    </aapt:attr>
</target>
</animated-vector>

我的活动xml中的导航视图组件如下所示

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="@dimen/bottom_navigation_height"
        android:layout_alignParentBottom="true"
        android:background="@color/primaryDarkColor"
        android:orientation="horizontal"
        app:itemIconTint="@color/bnv_tab_item_foreground"
        app:itemTextColor="@color/white"
        app:labelVisibilityMode="unlabeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_navigation_main" />

这是我的菜单文件:

<?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/action_home"
    android:enabled="true"
    android:icon="@drawable/home_fill"
    android:title="HOME"
    app:showAsAction="ifRoom"/>
<item
    android:id="@+id/action_notification"
    android:enabled="true"
    android:icon="@drawable/test"
    android:title="NOTIFICATION"
    app:showAsAction="ifRoom"/>
<item
    android:id="@+id/action_ride_history"
    android:enabled="true"
    android:icon="@drawable/history_fill"
    android:title="RIDE HISTORY"
    app:showAsAction="ifRoom"/>
<item
    android:id="@+id/action_menu_barger"
    android:enabled="true"
    android:icon="@drawable/menu"
    android:title="MENU"
    app:showAsAction="ifRoom"/>

</menu>

我想为第二个底部导航项设置动画,直到从加载活动视图中窃听为止

0 个答案:

没有答案