怎么在activity上画一个圆圈,点下按钮后圆圈不断变大,变化过程流畅一点,就像水面涟漪一样?
------解决方案--------------------
我试着写了一个,定义一个view,然后通过thread每隔1秒左右去draw这个圆圈,
下面是代码
MyView
- Java code
package wyf.ytl;import android.view.View;import android.graphics.Paint;import android.content.Context;import android.util.AttributeSet;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.RectF;public class MyView extends View { int iCycle = 0; //圆的半径10 int r = 10; // x,y坐标,320屏幕宽度,390屏幕高度,圆的直径20 int x = (320-2*r*0)/2; int y = (390-2*r*0)/2; public MyView(Context context,AttributeSet attrs){ super(context,attrs); } public MyView(Context context){ super(context); } protected void onDraw(Canvas canvas){ super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(Color.WHITE); if(iCycle < 5){ iCycle++; } else { iCycle = 0; } RectF rf1 = new RectF(x-r*iCycle,y-r*iCycle,x+r+r*iCycle,y+r+r*iCycle); canvas.drawOval(rf1, paint); } }