有两种类型的path:
1. 从 Svg
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/pathView"
android:layout_width="150dp"
android:layout_height="150dp"
app:pathColor="@android:color/white"
app:svg="@raw/settings"
app:pathWidth="5"/>
结果
2. 从 Path
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/pathView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:pathColor="@android:color/white"
app:pathWidth="3"/>
代码final Path path = new Path();
path.moveTo(0.0f, 0.0f);
path.lineTo(length / 4f, 0.0f);
path.lineTo(length, height / 2.0f);
path.lineTo(length / 4f, height);
path.lineTo(0.0f, height);
path.lineTo(length * 3f / 4f, height / 2f);
path.lineTo(0.0f, 0.0f);
path.close();
pathView.setPath(path);
结果
使用 animatorpathView.getPathAnimator()
.delay(100)
.duration(500)
.listenerStart(new AnimationListenerStart())
.listenerEnd(new AnimationListenerEnd())
.interpolator(new AccelerateDecelerateInterpolator())
.start();
如果想使用svg颜色pathView.useNaturalColors();
如果想在动画后绘制真正的SVGpathView.setFillAfter(true);
下载dependencies {
compile 'com.eftimoff:android-pathview:[email protected]'
}