android中SVG矢量图动画问题,((Animatable) drawable).start();异常

青竹健 2016-05-17 02:37:57
((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();
}
}
});
}
...全文
479 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ya_Michael 2017-12-07
  • 打赏
  • 举报
回复
解决了吗?我动画效果都不显示。.start()执行了
青竹健 2016-05-22
  • 打赏
  • 举报
回复
引用 6 楼 a_blesslp的回复:
[quote=引用 5 楼 青竹健的回复:][quote=引用 3 楼 a_blesslp的回复:]可以贴出你的imageview引用的矢量图xml吗,
在楼下贴出来了,麻烦帮我看看,谢谢哈[/quote] src换成app:srcCompat[/quote] 用app:srcCompat,xml文件报错,app在上面也生明了,大神你亲测有效吗
青竹健 2016-05-22
  • 打赏
  • 举报
回复
用app:srcCompat,xml文件报错,app在上面也生明了,大神你亲测有效吗
a_blesslp 2016-05-19
  • 打赏
  • 举报
回复
引用 5 楼 青竹健的回复:
[quote=引用 3 楼 a_blesslp的回复:]可以贴出你的imageview引用的矢量图xml吗,
在楼下贴出来了,麻烦帮我看看,谢谢哈[/quote] src换成app:srcCompat
青竹健 2016-05-18
  • 打赏
  • 举报
回复
引用 3 楼 a_blesslp的回复:
可以贴出你的imageview引用的矢量图xml吗,
在楼下贴出来了,麻烦帮我看看,谢谢哈
青竹健 2016-05-18
  • 打赏
  • 举报
回复
<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>
a_blesslp 2016-05-18
  • 打赏
  • 举报
回复
可以贴出你的imageview引用的矢量图xml吗,
青竹健 2016-05-17
  • 打赏
  • 举报
回复
引用 1 楼 a_blesslp的回复:
这个得android5.0以上,gradle 1.5以上,用AnimatedVectorDrawableCompat
环境是对的,你意思是把Drawable换成AnimatedVectorDrawableCompat吗
a_blesslp 2016-05-17
  • 打赏
  • 举报
回复
这个得android5.0以上,gradle 1.5以上,用AnimatedVectorDrawableCompat

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧