返回顶部

收藏

android实现水波纹效果的例子

更多
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");
    }
}
//该片段来自于http://outofmemory.cn

标签:java,手机开发

收藏

0人收藏

支持

0

反对

0

发表评论