android框架---->下沉文字Titanic的使用

  Titanic is a simple illusion obtained by applying an animated translation on the TextView TextPaint Shader's matrix.

 

Titanic的使用

Titanic的使用,项目结构如下:


一、下载Titanic并且部署到项目中

Titanic的项目地址: https://github.com/RomainPiel/Titanic

在项目中我们使用Titanic需要三个文件: Titanic.java、TitanicTextView.java和wave.png。当然wave.png是可以修改的,在TitanicTextView.java中引用了该资源。

 

二、它的使用比较简单,就是和普通的自定义View的使用一样

在xml中定义TitanicTextView

<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"

开始动画

titanic = new Titanic();
titanic.start(myTitanicTextView);

取消动画

titanic.cancel();

 

三、我们还可以修改它的字体,这也和普通的修改字体一样

在assets中引入ttf字体,在这里我们可以写一个有的帮助类Typefaces

package com.example.titanictextview;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;

import java.util.Hashtable;

/**
 * Created by Linux on 2016/6/9.
 */
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);
        }
    }
}

TitanicTextView的setText方法前,调用

titanicTextView.setTypeface(Typefaces.get(this, "Satisfy-Regular.ttf"));

 

四、运行效果如下

MainActivity.java:

package com.example.titanictextview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.romainpiel.titanic.library.Titanic;
import com.romainpiel.titanic.library.TitanicTextView;

public class MainActivity extends AppCompatActivity {

    private TitanicTextView titanicTextView;
    private Titanic titanic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        titanicTextView = (TitanicTextView) findViewById(R.id.titanic_tv);
        titanic = new Titanic();
    }

    // 点击开始
    public void startTitianic(View view) {
        titanicTextView.setTypeface(Typefaces.get(this, "Satisfy-Regular.ttf"));
        titanicTextView.setText("I love you!");
        titanic.start(titanicTextView);
    }

    // 点击结束
    public void cancelTitianic(View view) {
        titanic.cancel();
    }
}
View Code

 

友情链接

 

转载于:https://www.cnblogs.com/huhx/p/androidTitanicView.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值