80,349
社区成员
发帖
与我相关
我的任务
分享
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();
}
}
});
}
<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>