日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android Canvas 绘图

發布時間:2025/5/22 Android 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android Canvas 绘图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

畫圖
http://www.2cto.com/kf/201404/296296.html
http://blog.csdn.net/tianjian4592/article/details/44783283
http://blog.csdn.net/wangfayinn/article/details/8685310
http://www.cnblogs.com/tianzhijiexian/p/4298660.html

?

?

實現一個自定義的進度條

public class ArcProgress extends View {private Paint paint;private RectF rectF = new RectF();private float strokeWidth;private int progress = 0;private int max;private float arcAngle;private final float default_stroke_width;private final int default_max = 100;private final float default_arc_angle = 360;public ArcProgress(Context context) {this(context, null);}public ArcProgress(Context context, AttributeSet attrs) {this(context, attrs, 0);}public ArcProgress(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);default_stroke_width = Utils.dp2px(context, 4);TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ArcProgress, defStyleAttr, 0);initByAttributes(attributes);attributes.recycle();}protected void initByAttributes(TypedArray attributes) {arcAngle = attributes.getDimension(R.styleable.ArcProgress_arc_angle,default_arc_angle);setMax(attributes.getInt(R.styleable.ArcProgress_arc_max, default_max));setProgress(attributes.getInt(R.styleable.ArcProgress_arc_progress, 0));strokeWidth = attributes.getDimension(R.styleable.ArcProgress_arc_stroke_width, default_stroke_width);}@Overridepublic void invalidate() {super.invalidate();}public int getProgress() {return progress;}public void setProgress(int progress) {this.progress = progress;if (this.progress > getMax()) {this.progress %= getMax();}invalidate();}public int getMax() {return max;}public void setMax(int max) {if (max > 0) {this.max = max;invalidate();}}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);float startAngle = 90 - arcAngle / 2f;float finishedSweepAngle = progress / (float) getMax() * arcAngle;float finishedStartAngle = startAngle;int width = getMeasuredWidth();rectF.set(strokeWidth / 2f, strokeWidth / 2f,getMeasuredWidth() - strokeWidth / 2f,getMeasuredWidth() - strokeWidth / 2f);paint = new Paint();paint.setAntiAlias(true);paint.setStrokeWidth(strokeWidth);paint.setStyle(Paint.Style.STROKE);paint.setStrokeCap(Paint.Cap.ROUND);Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.uu_loading_bg);bitmap = Bitmap.createScaledBitmap(bitmap, width, width, false);// 可以使用圖片座位畫筆 注意圖片可以設置為平鋪 拉伸這些屬性paint.setShader(new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));// 可以使用變換屬性來實現一些效果canvas.scale((float) 0.9, (float) 0.9, width / 2, width / 2);// 繪制圓弧 等矩形圖形canvas.drawArc(rectF, startAngle, arcAngle, false, paint);bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.uu_loading);bitmap = Bitmap.createScaledBitmap(bitmap, width, width, false);paint.setShader(new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));canvas.drawArc(rectF, finishedStartAngle, finishedSweepAngle, false, paint);// 可以對位圖來進行一些變換 效果然后繪制上去Bitmap bitmap_loadingpoint = BitmapFactory.decodeResource(getResources(), R.drawable.uu_loadingpoint);Matrix matrix = new Matrix();matrix.setTranslate(bitmap_loadingpoint.getHeight() / 2, bitmap_loadingpoint.getHeight() / 2);matrix.postRotate(finishedSweepAngle + 45, getWidth() / 2, getWidth() / 2);canvas.drawBitmap(bitmap_loadingpoint, matrix, null);} }

?

轉載于:https://www.cnblogs.com/xbx2015/p/5716574.html

總結

以上是生活随笔為你收集整理的Android Canvas 绘图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。