闲来无事,某天上网链接到燎原网站(http://liaoyuan.io/)时发现背景的动态效果挺不错的,故移到android上面实现之。代码不也很简单多,直接贴上以供参考。由于是动态刷新,所以使用了surfaceview来处理,用view应该也可以。
网站效果图:
实现效果:
ParticleView.java
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class ParticleViewextends SurfaceView implements SurfaceHolder.Callback {
public static final int TIME_INTERVAL = 100;
private DrawThread drawThr;
private static final int PART_NUM = 20;
private static final int CIRCLE = 2;
private static final int COUNTER_DIS = 100;
private ArrayList<Particle> mParticles;
pri