看到飘落的雪花让我想起了飘落的字体
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("安卓巴士");
}
}以上便完成了字体下落动画,效果图展示:
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
