亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

自定義飄落的字體

標簽:
Android

看到飘落的雪花让我想起了飘落的字体
1.首先自定义一个view继承View

public class fallView extends View{

}

2.实现fallView中的方法:在方法中初始化屏幕宽度、画笔、要执行的时间

public fallView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // 初始化
    w = context.getResources().getDisplayMetrics().widthPixels;
    h = context.getResources().getDisplayMetrics().heightPixels;

    initPaint();

    new Thread(runnable).start(); // 开启线程
}

3.添加绘画的布:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    
    DrawLine(canvas,s, x, y, paint);

}
private void DrawLine(Canvas canvas,String s, int[] x2, int[] y2, Paint paint2) {

    for(int i =0 ; i<NUM;i++){

        canvas.drawText( s , x[i], y[i], paint);

    }
}

4.存储数据并且对外展示接口set

//存储的数据
private String s ;

public String getPollutant(){

    return s;
}
public void setPollutant(String s){

    this.s = s;
}

5.在该调用的地方调用:xml布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000">

    <fall.huihui.com.fallView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/fall"/>

</RelativeLayout>

6.activity或者fragment中设置:

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

public class MainActivity extends AppCompatActivity {

    private fallView fall;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fall = (fallView) findViewById(R.id.fall);
        fall.setPollutant("安卓巴士");
    }
}

以上便完成了字体下落动画,效果图展示:

5ba3bd9400019f2210801920.jpg

原文链接:http://www.apkbus.com/blog-784586-63151.html

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消