public class TitanicMainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_imitate_titanic_main); TitanicTextView tv = (TitanicTextView) findViewById(R.id.my_text_view); // set fancy typeface tv.setTypeface(Typefaces.get(this, "Satisfy-Regular.ttf")); // start animation new Titanic().start(tv); }}
import android.content.Context; import android.graphics.Typeface; import android.util.Log; import java.util.Hashtable; public class Typefaces { private static final String TAG = "Typefaces"; private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>(); public static Typeface 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; } } return cache.get(assetPath); } } }
水纹上升的动画
最新推荐文章于 2021-05-26 00:06:04 发布