色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

Android自定義圓形進度條效果

瀏覽:4日期:2022-09-19 13:16:00

本文實例為大家分享了Android自定義圓形進度條效果的具體代碼,供大家參考,具體內容如下

1 控件 RoundProgress

package listview.tianhetbm.p2p.ui;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.util.AttributeSet;import android.util.Log;import android.view.View;import listview.tianhetbm.p2p.R;/** * @date:2015/9/14 * @author:dongxiaogang * @description: 自定義圓形進度條 */public class RoundProgress extends View { private Paint paint = new Paint(); private int roundColor; private int roundProgressColor; private int textColor; private float textSize; private float roundWidth; private int max = 100; private int progress = 50; public RoundProgress(Context context) {this(context, null); } public RoundProgress(Context context, AttributeSet attrs) {this(context, attrs, 0); } public RoundProgress(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RoundProgress);//圓環的顏色roundColor = ta.getColor(R.styleable.RoundProgress_roundColor, Color.RED);//圓環進度的顏色roundProgressColor = ta.getColor(R.styleable.RoundProgress_roundProgressColor, Color.GREEN);//中間進度百分比文字字符串的顏色textColor = ta.getColor(R.styleable.RoundProgress_textColor, Color.GREEN);//中間進度百分比的字符串的字體大小textSize = ta.getDimension(R.styleable.RoundProgress_textSize, 15);//圓環的寬度roundWidth = ta.getDimension(R.styleable.RoundProgress_roundWidth, 5);ta.recycle(); } @Override protected void onDraw(Canvas canvas) {//第一步:繪制一個最外層的圓paint.setColor(roundColor);paint.setStrokeWidth(roundWidth);paint.setStyle(Paint.Style.STROKE);paint.setAntiAlias(true);int center = getWidth() / 2;int radius = (int) (center - roundWidth / 2-45);//canvas.drawCircle(center, center, radius, paint);RectF oval = new RectF(center - radius, center - radius, center + radius, center + radius);canvas.drawArc(oval, 135, 270, false, paint);//第二步:繪制正中間的文本float textWidth = paint.measureText(progress + '%');paint.setColor(textColor);paint.setTextSize(textSize);paint.setStrokeWidth(0);canvas.drawText(progress + '%', center - textWidth / 2, center + textSize / 2, paint);//第三步:/** * 參數解釋: * oval:繪制弧形圈所包含的矩形范圍輪廓 * 0:開始的角度 * 360 * progress / max:掃描過的角度 * false:是否包含圓心 * paint:繪制弧形時候的畫筆 *///RectF oval = new RectF(center - radius, center - radius, center + radius, center + radius);paint.setColor(roundProgressColor);paint.setStrokeWidth(roundWidth);paint.setStyle(Paint.Style.STROKE);canvas.drawArc(oval, 135, 270 * progress / max, false, paint);Log.e('測試角度',(270 * progress / max)+'');Paint mp=new Paint();mp.setAntiAlias(true);Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.tiger);int bitmapHeight = bitmap.getHeight()/2;int bitmapWidth = bitmap.getWidth()/2;//canvas.translate(-center, center);float y=0f,x=0f;//if(270 * progress / max<=45){ y = (float) (center-bitmapWidth - (radius) * Math.cos((270 * progress / max+225)*Math.PI/180)); x = (float) (center-bitmapWidth + (radius) * Math.sin((270 * progress / max+225)*Math.PI/180));//} //canvas.translate(center, center*2); Log.e('測試角度', y + '-----' + x); canvas.drawBitmap(bitmap, x, y, mp); } public void setProgress(int progress){this.progress = progress;if(progress>100){ this.progress = 100;}postInvalidate(); }}2 xml 布局文件

<?xml version='1.0' encoding='utf-8'?><RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' android:layout_width='match_parent' android:layout_height='match_parent' android:gravity='center_horizontal'> <listview.tianhetbm.p2p.ui.RoundProgressandroid:layout_marginTop='30dp'android:layout_width='250dp'android:layout_height='250dp'android:layout_marginLeft='10dp'app:roundColor='@color/back_blue'app:roundProgressColor='@color/back_orange'android: app:roundWidth='10dp'app:textSize='18sp'app:textColor='@color/record_red'/></RelativeLayout>3 activity(主要代碼)

super.onCreate(savedInstanceState);setContentView(R.layout.activity_main_three);ButterKnife.bind(this);new Thread(){ @Override public void run() { while (progress<80){ progress+=1; ce.setProgress(progress); try { Thread.sleep(50); } catch (Exception e) { e.printStackTrace(); } } }}.start();

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 毛片免费永久不卡视频观看 | 亚洲第一网站在线观看 | 久久视频免费在线观看 | 久草热久草在线 | 精品72久久久久久久中文字幕 | 欧美一级毛片日本 | 亚洲成人www | 成人欧美网站免费 | 老司机深夜影院入口aaaa | 男人性天堂 | 理论片黄色 | 乱人伦中文视频在线观看免费 | 日本欧美一区二区三区视频 | 欧美一级片在线播放 | 男人桶女人暴爽的视频 | 国产成人亚洲欧美三区综合 | 免费看香港一级毛片 | 欧美三级在线视频 | 131的美女午夜爱爱爽爽视频 | 久99久精品视频免费观看v | 美女超爽久久久久网站 | 97在线观看| 日韩综合色 | 成人黄色在线网站 | 特黄a大片免费视频 | 欧美国产日韩在线播放 | 一区免费在线观看 | 亚洲免费网站观看视频 | 91精品国产免费久久久久久青草 | 综合在线视频精品专区 | 欧美成人看片一区二区三区尤物 | 亚洲欧美日韩高清综合678 | www.99在线观看 | 久久中精品中文 | 1024手机基地在线看手机 | 一级毛片成人免费看免费不卡 | 亚洲欧美日韩一区 | 女让张开腿让男人桶视频 | 欧美精品久久天天躁 | 九九亚洲精品自拍 | 天堂中文资源在线8 |