关闭

透明度的layerDemo

标签: 层叠图layerAndroid
304人阅读 评论(0) 收藏 举报
分类:
package com.example.xfermodesdemo;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class LayerActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		private static final int LAYER_FLAGS = Canvas.MATRIX_SAVE_FLAG
				| Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
				| Canvas.FULL_COLOR_LAYER_SAVE_FLAG
				| Canvas.CLIP_TO_LAYER_SAVE_FLAG;

		/** 画笔 */
		private Paint mPaint;

		public SampleView(Context context) {
			super(context);
			setFocusable(true);

			mPaint = new Paint();
			mPaint.setAntiAlias(true);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			canvas.drawColor(Color.WHITE);

			canvas.translate(10, 10);

			canvas.saveLayerAlpha(0, 0, 200, 200, 0x88, LAYER_FLAGS);

			mPaint.setColor(Color.RED);
			canvas.drawCircle(75, 75, 75, mPaint);
			mPaint.setColor(Color.BLUE);
			canvas.drawCircle(125, 125, 75, mPaint);

			canvas.restore();
			// Paint p1 = new Paint(Paint.ANTI_ALIAS_FLAG);
			// p1.setColor(0xFF00FF00);
			// mPaint.setColor(0xFF00FF00);
			// canvas.drawRect(10, 10, 100, 100, p1);
			// Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
			// p.setColor(0xFF0000FF);
			// canvas.drawRect(80, 80, 180, 180, p);
		}
	}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:48053次
    • 积分:1608
    • 等级:
    • 排名:千里之外
    • 原创:113篇
    • 转载:36篇
    • 译文:0篇
    • 评论:1条