((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();
}
}
});
}
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();
}
}
});
}
解决方案 »
- Android开发多层树型目录的实现
- 视频监控软件,想在里面实现录像的功能。用bitmap描绘的图像,怎么能实现录像?
- 请问关于android中数据问题
- 安卓的九宫图问题
- surfaceView 来电问题 (急~~~~~~~~~~~~~)
- 大家推荐个好用的收费vpn吧
- android模拟器上卸载程序
- 实现监听安装apk确定的按钮建,怎么解?
- 求问在安卓客户端中怎么实现调查问卷
- android-sdk_r10-windows
- 用OKhttp请求服务器,无法获取数据。用自己建的tomcat本地服务器能获取到数据,所以很不解请大家帮忙看看谢谢!
- Error:warning: Ignoring InnerClasses attribute for an anonymous inner class 银联
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>
src换成app:srcCompat
src换成app:srcCompat
用app:srcCompat,xml文件报错,app在上面也生明了,大神你亲测有效吗