多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > php開(kāi)源 > 綜合技術(shù) > Android的下拉刷新帶進(jìn)度條效果

Android的下拉刷新帶進(jìn)度條效果

來(lái)源:程序員人生   發(fā)布時(shí)間:2015-01-20 08:08:22 閱讀次數(shù):3336次

         首先看1下運(yùn)行效果圖,程序的下拉刷新參考了視頻,在視頻頁(yè)面也提供了源碼下載,

http://www.imooc.com/learn/135


本篇主要說(shuō)在此基礎(chǔ)上增加了進(jìn)度條的快速旋轉(zhuǎn)和遞增遞減處理,在文章最后也會(huì)給出源碼,這里主要描寫1下所用的1個(gè)類

RoundProgressBar

package com.cayden.listview; 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.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.view.View; /** * 帶進(jìn)度的進(jìn)度條,線程安全的View,可直接在線程中更新進(jìn)度 * @author cuiran * */ public class RoundProgressBar extends View { /** * 畫(huà)筆對(duì)象的援用 */ private Paint paint; /** * 圓環(huán)的色彩 */ private int roundColor; /** * 圓環(huán)進(jìn)度的色彩 */ private int roundProgressColor; /** * 中間進(jìn)度百分比的字符串的色彩 */ private int textColor; /** * 中間進(jìn)度百分比的字符串的字體 */ private float textSize; /** * 圓環(huán)的寬度 */ private float roundWidth; /** * 最大進(jìn)度 */ private int max; /** * 當(dāng)前進(jìn)度 */ private int progress; /** * 是不是顯示中間的進(jìn)度 */ private boolean textIsDisplayable; /** * 進(jìn)度的風(fēng)格,實(shí)心或空心 */ private int style; public static final int STROKE = 0; public static final int FILL = 1; /**是不是循環(huán)**/ public boolean isSpinning = false; public RoundProgressBar(Context context) { this(context, null); } public RoundProgressBar(Context context, AttributeSet attrs) { this(context, attrs, 0); } public RoundProgressBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); paint = new Paint(); TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundProgressBar); //獲得自定義屬性和默許值 roundColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundColor, Color.RED); roundProgressColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundProgressColor, Color.GREEN); textColor = mTypedArray.getColor(R.styleable.RoundProgressBar_textColor, Color.GREEN); textSize = mTypedArray.getDimension(R.styleable.RoundProgressBar_textSize, 15); roundWidth = mTypedArray.getDimension(R.styleable.RoundProgressBar_roundWidth, 5); max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, 360); textIsDisplayable = mTypedArray.getBoolean(R.styleable.RoundProgressBar_textIsDisplayable, true); style = mTypedArray.getInt(R.styleable.RoundProgressBar_style, 0); mTypedArray.recycle();//必須Recycle } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); /** * 畫(huà)最外層的大圓環(huán) */ int centre = getWidth()/2; //獲得圓心的x坐標(biāo) int radius = (int) (centre - roundWidth/2); //圓環(huán)的半徑 paint.setColor(roundColor); //設(shè)置圓環(huán)的色彩 paint.setStyle(Paint.Style.STROKE); //設(shè)置空心 paint.setStrokeWidth(roundWidth); //設(shè)置圓環(huán)的寬度 paint.setAntiAlias(true); //消除鋸齒 canvas.drawCircle(centre, centre, radius, paint); //畫(huà)出圓環(huán) /** * 畫(huà)進(jìn)度百分比 現(xiàn)已去掉改成畫(huà)圖片 */ // paint.setStrokeWidth(0); // paint.setColor(textColor); // paint.setTextSize(textSize); // paint.setTypeface(Typeface.DEFAULT_BOLD); //設(shè)置字體 // int percent = (int)(((float)progress / (float)max) * 100); //中間的進(jìn)度百分比,先轉(zhuǎn)換成float在進(jìn)行除法運(yùn)算,不然都為0 // float textWidth = paint.measureText(percent + "%"); //丈量字體寬度,我們需要根據(jù)字體的寬度設(shè)置在圓環(huán)中間 // // if(textIsDisplayable && percent != 0 && style == STROKE){ // canvas.drawText(percent + "%", centre - textWidth / 2, centre + textSize/2, paint); //畫(huà)出進(jìn)度百分比 // } if(isSpinning){ /** * 畫(huà)圖片 */ Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.loading02); int width=bitmap.getWidth(); int height=bitmap.getHeight(); canvas.drawBitmap(bitmap, centre-width/2, centre-height/2 , paint); bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.loading06); width=bitmap.getWidth(); height=bitmap.getHeight(); canvas.drawBitmap(bitmap, centre-width/2, centre-height/2 , paint); /** * 畫(huà)圓弧 ,畫(huà)圓環(huán)的進(jìn)度 */ //設(shè)置進(jìn)度是實(shí)心還是空心 paint.setStrokeWidth(roundWidth); //設(shè)置圓環(huán)的寬度 paint.setColor(roundProgressColor); //設(shè)置進(jìn)度的色彩 RectF oval = new RectF(centre - radius, centre - radius, centre + radius, centre + radius); //用于定義的圓弧的形狀和大小的界限 paint.setStyle(Paint.Style.STROKE); canvas.drawArc(oval, progress⑼0, 320 , false, paint); //根據(jù)進(jìn)度畫(huà)圓弧 }else{ /** * 畫(huà)圖片 */ Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.loading02); int width=bitmap.getWidth(); int height=bitmap.getHeight(); canvas.drawBitmap(bitmap, centre-width/2, centre-height/2 , paint); bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.loading05); width=bitmap.getWidth(); height=bitmap.getHeight(); canvas.drawBitmap(bitmap, centre-width/2, centre-height/2 , paint); /** * 畫(huà)圓弧 ,畫(huà)圓環(huán)的進(jìn)度 */ //設(shè)置進(jìn)度是實(shí)心還是空心 paint.setStrokeWidth(roundWidth); //設(shè)置圓環(huán)的寬度 paint.setColor(roundProgressColor); //設(shè)置進(jìn)度的色彩 RectF oval = new RectF(centre - radius, centre - radius, centre + radius, centre + radius); //用于定義的圓弧的形狀和大小的界限 paint.setStyle(Paint.Style.STROKE); canvas.drawArc(oval, ⑼0, progress , false, paint); //根據(jù)進(jìn)度畫(huà)圓弧 } } public synchronized int getMax() { return max; } /** * 設(shè)置進(jìn)度的最大值 * @param max */ public synchronized void setMax(int max) { if(max < 0){ throw new IllegalArgumentException("max not less than 0"); } this.max = max; } /** * 獲得進(jìn)度.需要同步 * @return */ public synchronized int getProgress() { return progress; } /** * Reset the count (in increment mode) */ public void resetCount() { progress = 0; invalidate(); } /** * Turn off spin mode */ public void stopSpinning() { isSpinning = false; progress = 0; spinHandler.removeMessages(0); } /** * Puts the view on spin mode */ public void spin() { isSpinning = true; spinHandler.sendEmptyMessage(0); } /** * Increment the progress by 1 (of 360) */ public void incrementProgress() { isSpinning = false; if (progress > 360) progress = 0; spinHandler.sendEmptyMessage(0); } private Handler spinHandler = new Handler() { /** * This is the code that will increment the progress variable * and so spin the wheel */ @Override public void handleMessage(Message msg) { invalidate(); if(isSpinning){ progress += 10; if (progress > 360) { progress = 0; } spinHandler.sendEmptyMessageDelayed(0, 0); } //super.handleMessage(msg); } }; /** * 設(shè)置進(jìn)度,此為線程安全控件,由于斟酌多線的問(wèn)題,需要同步 * 刷新界面調(diào)用postInvalidate()能在非UI線程刷新 * @param progress */ public synchronized void setProgress(int progress) { if(progress < 0){ throw new IllegalArgumentException("progress not less than 0"); } if(progress > max){ progress = max; } if(progress <= max){ this.progress = progress; postInvalidate(); } } public int getCricleColor() { return roundColor; } public void setCricleColor(int cricleColor) { this.roundColor = cricleColor; } public int getCricleProgressColor() { return roundProgressColor; } public void setCricleProgressColor(int cricleProgressColor) { this.roundProgressColor = cricleProgressColor; } public int getTextColor() { return textColor; } public void setTextColor(int textColor) { this.textColor = textColor; } public float getTextSize() { return textSize; } public void setTextSize(float textSize) { this.textSize = textSize; } public float getRoundWidth() { return roundWidth; } public void setRoundWidth(float roundWidth) { this.roundWidth = roundWidth; } }

類中的主要繪圖部份在

canvas.drawArc(oval, progress⑼0, 320 , false, paint);  //根據(jù)進(jìn)度畫(huà)圓弧

canvas.drawArc(oval, ⑼0, progress , false, paint);  //根據(jù)進(jìn)度畫(huà)圓弧

可以看1下canvas.drawArc方法

public void drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)

  • oval :指定圓弧的外輪廓矩形區(qū)域。
  • startAngle: 圓弧起始角度,單位為度。
  • sweepAngle: 圓弧掃過(guò)的角度,順時(shí)針?lè)较?,單位為度?/li>
  • useCenter: 如果為True時(shí),在繪制圓弧時(shí)將圓心包括在內(nèi),通經(jīng)常使用來(lái)繪制扇形。
  • paint: 繪制圓弧的畫(huà)板屬性,如色彩,是不是填充等
可以參考以下對(duì)此介紹的網(wǎng)站

http://blog.sina.com.cn/s/blog_783ede0301012im3.html



最后給出項(xiàng)目的源碼:

https://github.com/cayden/ListViewDemo


生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 乌克兰xxxx| 精品亚洲福利一区二区 | 国产日产欧产精品精品推荐小说 | 国内久久精品 | 国产精品国产三级国产无毒 | 天天亚洲综合 | 性鸥美| 一区二区三区在线观看视频 | 免费一级毛片在播放视频 | 国产精品a区 | jiujiure精品| 国产不卡在线视频 | 激情久久久久久久久久久 | 欧美另类亚洲一区二区 | 美女的隐私视频网站蜜桃视频 | 欧美亚洲国产色综合 | 图片区亚洲 | 久久精品国产精品亚洲精品 | 亚洲综合激情另类小说区 | 永久免费毛片在线播放 | 动漫精品在线 | 羞羞视频免费网站入口 | 成人欧美一区二区三区黑人 | 日本免费一区二区三区三州 | 国产伦精品一区二区三区在线观看 | freexxx性欧美极品另类 | 国产精品乱码一区二区三区 | 久久96国产精品久久久 | 日本一区二区三 | 国农村精品国产自线拍 | 欧美一区二区三区不卡视频 | 亚洲国产欧美久久香综合 | 边吃奶边添下面就爽 | 18一19xxx日本护士 | 国产精品久久久久影视不卡 | 亚欧精品在线观看 | 欧美大片天天免费看视频 | 欧美日韩午夜视频 | 性生一级欧美片 | 在线 丝袜 欧美 日韩 制服 | 久久久久在线观看 |