RippleDrawable
或自定义View。以下是一个简单的示例代码:,,``java,// 在res/drawable目录下创建一个ripple_effect.xml文件,,,,,,,,,// 在布局文件中使用该drawable作为背景,,
``,,这段代码创建了一个带有水波纹效果的按钮,当用户点击按钮时,会显示一个扩散的水波纹动画。java,Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);,startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);,
``java,public class LuckyWheel extends View {, private Paint paint;, private int[] colors = {Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW};, private String[] texts = {"奖品1", "奖品2", "奖品3", "奖品4"};, private int centerX, centerY, radius;,, public LuckyWheel(Context context) {, super(context);, init();, },, private void init() {, paint = new Paint();, paint.setAntiAlias(true);, paint.setTextSize(50);, paint.setStyle(Paint.Style.FILL);, },, @Override, protected void onDraw(Canvas canvas) {, super.onDraw(canvas);, centerX = getWidth() / 2;, centerY = getHeight() / 2;, radius = Math.min(centerX, centerY) 100;,, for (int i = 0; i< 4; i++) {, paint.setColor(colors[i]);, canvas.drawArc(new RectF(centerX radius, centerY radius, centerX + radius, centerY + radius), i * 90 45, 90, true, paint);, drawText(canvas, i);, }, },, private void drawText(Canvas canvas, int index) {, paint.setColor(Color.WHITE);, float angle = (index * 90 + 45) * (float) Math.PI / 180;, float x = (float) (centerX + radius * Math.cos(angle));, float y = (float) (centerY + radius * Math.sin(angle));, canvas.drawText(texts[index], x, y, paint);, },},
``Powered By Z-BlogPHP 1.7.3