Titanic is a simple illusion obtained by applying an animated translation on the TextView textpaint Shader ' s matrix.
Use of Titanic
Titanic, the project structure is as follows:
First, download the Titanic and deploy to the project,
Titanic's project address: Https://github.com/RomainPiel/Titanic.
In the project we need three files to use Titanic: Titanic.java, Titanictextview.java, and Wave.png. Of course wave.png can be modified, and the resource is referenced in the Titanictextview.java.
Second, its use is relatively simple, is the same as the normal use of custom view.
Defining Titanictextview in XML
< Com.romainpiel.titanic.library.TitanicTextView Android:id = "@+id/titanic_tv" android:layout_width= "Wrap_content" android:layout_height= "Wrap_ Content " android:textcolor=" #212121 " android:textsize=" 70SP "
Start animation
New Titanic (); Titanic.start (Mytitanictextview);
Cancel Animation
Titanic.cancel ();
Third, we can also modify its font, which is the same as the normal modification of the font.
Introducing TTF fonts in assets, where we can write a helper class typefaces
PackageCom.example.titanictextview;ImportAndroid.content.Context;ImportAndroid.graphics.Typeface;ImportAndroid.util.Log;Importjava.util.Hashtable;/*** Created by Linux on 2016/6/9.*/ Public classtypefaces {Private Static FinalString TAG = "typefaces"; Private Static Finalhashtable<string, typeface> cache =NewHashtable<string, typeface>(); Public StaticTypeface Get (Context C, String Assetpath) {synchronized(cache) {if(!Cache.containskey (Assetpath)) { Try{Typeface T=Typeface.createfromasset (C.getassets (), Assetpath); Cache.put (Assetpath, T); } Catch(Exception e) {log.e (TAG,"Could not get typeface '" + Assetpath + "' because" +e.getmessage ()); return NULL; } } returnCache.get (Assetpath); } }}
Titanictextview before the SetText method, call the
Titanictextview.settypeface (Typefaces.get (This, "Satisfy-regular.ttf"));
Four, the operation effect is as follows:
Mainactivity.java:
PackageCom.example.titanictextview;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.View;ImportCom.romainpiel.titanic.library.Titanic;ImportCom.romainpiel.titanic.library.TitanicTextView; Public classMainactivityextendsappcompatactivity {PrivateTitanictextview Titanictextview; PrivateTitanic Titanic; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Titanictextview=(Titanictextview) Findviewbyid (R.ID.TITANIC_TV); Titanic=NewTitanic (); } //Click to start Public voidstarttitianic (view view) {Titanictextview.settypeface (Typefaces.get ( This, "Satisfy-regular.ttf")); Titanictextview.settext ("I Love you!"); Titanic.start (Titanictextview); } //Click End Public voidcanceltitianic (view view) {Titanic.cancel (); }}
View Code
Friendship Link
Android Frame----> Sinking text Titanic use