((Animatable) drawable).start();启动矢量图的动画异常,然后根据博客上加了个 if (drawable instanceof Animatable) ;可是直接就执行else语句了,动画无法执行,看源码,Drawable没有实现Animatable接口,那么其他人是怎样通过这个方式启动动画的呢?做过的人麻烦指导一下。下面是代码
my_image = (ImageView) findViewById(R.id.my_image);
        my_image.setOnClickListener(new View.OnClickListener() {            @Override
            public void onClick(View v) {
                try {
                    Drawable drawable = my_image.getDrawable();
                    if (drawable instanceof Animatable) {
                        ((Animatable) drawable).start();
                    } else {
                        Toast.makeText(MainActivity.this, "No", Toast.LENGTH_SHORT).show();
                    }                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, "111 :" + e.toString(), Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

解决方案 »

  1.   

    这个得android5.0以上,gradle 1.5以上,用AnimatedVectorDrawableCompat
      

  2.   

    环境是对的,你意思是把Drawable换成AnimatedVectorDrawableCompat吗
      

  3.   

    可以贴出你的imageview引用的矢量图xml吗, 
      

  4.   

    <ImageView
            android:id="@+id/my_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/trick"
            />imageview引用的矢量图xml:
    <vector
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:height="200dp"
        android:width="200dp"
        android:viewportHeight="100"
        android:viewportWidth="100">
        <group>
            <path
                android:name="path1"
                android:strokeColor="@android:color/holo_green_dark"
                android:strokeWidth="5"
                android:strokeLineCap="round"
                android:pathData="M 20,80
                L 50,80 80,80"/>
            <path
                android:name="path2"
                android:strokeColor="@android:color/holo_green_dark"
                android:strokeWidth="5"
                android:strokeLineCap="round"
                android:pathData="M 20,20
                L 50,20 80,20"/>
        </group>
    </vector>
    动画XML:
    <animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/trick">
        <target
            android:name="path1"
            android:animation="@animator/animator"
            />
        <target
            android:name="path2"
            android:animation="@animator/animator_two"
            />
    </animated-vector>
      

  5.   

    在楼下贴出来了,麻烦帮我看看,谢谢哈
    src换成app:srcCompat
      

  6.   

    用app:srcCompat,xml文件报错,app在上面也生明了,大神你亲测有效吗
      

  7.   

    在楼下贴出来了,麻烦帮我看看,谢谢哈
    src换成app:srcCompat
    用app:srcCompat,xml文件报错,app在上面也生明了,大神你亲测有效吗
      

  8.   

    解决了吗?我动画效果都不显示。.start()执行了