今天学了一个新的框架PathView,这个框架主要是svg通过path来绘制动画,Github地址为:https://github.com/geftimov/android-pathview,如果你有图片但是没有svg的话,你可以使用工具将图片转为svg。在线转换工具:https://image.online-convert.com/convert-to-svg
使用步骤
- 首先你需要一个svg图片,将其放到raw文件夹中。
- 然后将控件显示在界面中,代码如下:
<com.eftimoff.androipathview.PathView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/path_view"
android:layout_width="150dp"
android:layout_height="150dp"
app:pathColor="@color/colorAccent"
app:pathWidth="5dp"
app:svg="@raw/logo" />
其中pathWidth要用dp。
3. 在代码中获取控件,并进行配置。代码如下:
mPathView.getPathAnimator().delay(100).duration(5000).listenerEnd(new PathView.AnimatorBuilder.ListenerEnd() {
@Override
public void onAnimationEnd() {
jump();
}
}).start();