.
introduce
use
TextPathView is a custom control that transforms text into path animation and then displays it. The effect is shown above.
Gradle
compile 'com.yanzhikai:TextPathView:0.1.3'
minSdkVersion 16
If you encounter a problem that disappears after playing, turn off hardware acceleration, which may not support the drawPath() method
How to use
TextPathView
TextPathView is divided into two types, one is SyncTextPathView that each stroke depicts in order, and the other is AsyncTextPathView that each stroke depicts at the same time. The use method is the same. Configure the attribute in xml, and then directly call startAnimation() method in java. See the example and demo for details. Here is a simple example:
In xml:
<yanzhikai.textpath.SyncTextPathView android:id="@+id/stpv_2017" android:layout_width="match_parent" android:layout_height="wrap_content" app:duration="12000" app:showPainter="true" app:text="2017" app:textInCenter="true" app:textSize="60sp" android:layout_weight="1" /> <yanzhikai.textpath.AsyncTextPathView android:id="@+id/atpv_1" android:layout_width="wrap_content" android:layout_height="wrap_content" app:duration="12000" app:showPainter="true" app:text="Flaming armor" app:textStrokeColor="@android:color/holo_orange_light" app:textInCenter="true" app:textSize="62sp" android:layout_gravity="center_horizontal" />
java uses:
atpv1 = findViewById(R.id.atpv_1); stpv_2017 = findViewById(R.id.stpv_2017); //From none to display atpv1.startAnimation(0,1); //From display to disappear stpv_2017.startAnimation(1,0);
You can also control the TextPathView display by controlling the progress. Here, SeekBar:
sb_progress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { atpv1.drawPath(progress / 1000f); stpv_2017.drawPath(progress / 1000f); } }
PathView
PathView is new after version 0.1.1. It has three subclasses: TextPathView, SyncPathView and AsyncPathView. The former has a text Path, and the latter two are graphic paths. You must enter a Path class to run normally:
public class TestPath extends Path { public TestPath(){ init(); } private void init() { addCircle(350,300,150,Direction.CCW); addCircle(350,300,100,Direction.CW); addCircle(350,300,50,Direction.CCW); moveTo(350,300); lineTo(550,500); } }
//setPath must be called first to set the path aspv.setPath(new TestPath()); aspv.startAnimation(0,1);
Only so many functions are used
Author's address: https://github.com/totond/TextPathView