android实现水波纹效果的例子
openkk
13年前
public class AnimActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(new PlasmaView(this)); } } class PlasmaView extends View implements View.OnTouchListener{ private Bitmap mBitmap; long time; long fps; public PlasmaView(Context context) { super(context); Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.mm); mBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.RGB_565); AnimRender.setBitmap(bmp); this.setOnTouchListener(this); } @Override protected void onDraw(Canvas canvas) { long ct = System.currentTimeMillis(); if(ct - time > 1000){ Log.v("Fps:" + String.valueOf(fps)); time = ct; fps = 0; } //fps++; fps += 20; AnimRender.render(mBitmap); canvas.drawBitmap(mBitmap, 0, 0, null); postInvalidate(); } @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub AnimRender.drop((int)event.getX(), (int)event.getY(), 1200); return false; } } class AnimRender{ public static native void setBitmap(Bitmap src); public static native void render(Bitmap dst); public static native void drop(int x, int y, int height); static { System.loadLibrary("plasma"); } }