Android Frame----> Sinking text Titanic use

Source: Internet
Author: User

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://

In the project we need three files to use Titanic:,, and Wave.png. Of course wave.png can be modified, and the resource is referenced in the

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.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:

 PackageCom.example.titanictextview;ImportAndroid.os.Bundle;;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.