最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)簡(jiǎn)單實(shí)用的垂直進(jìn)度條

 更新時(shí)間:2022年07月27日 15:32:45   作者:Jiang灬Hua  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)單實(shí)用的垂直進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)簡(jiǎn)單垂直進(jìn)度條的具體代碼,供大家參考,具體內(nèi)容如下

代碼注釋特別清晰,就不多解釋了

支持屬性:

  • progress_radius     進(jìn)度條圓角大小
  • progress_border_enable  進(jìn)度條是否有邊框
  • progress_gradient_enable 進(jìn)度條顏色是否漸變
  • progress_start_color     從上到下進(jìn)度條開始的漸變色
  • progress_end_color    從上到下進(jìn)度條結(jié)束的漸變色
  • progress_solid_color    帶邊框進(jìn)度條的背景填充色
  • progress_border_color    進(jìn)度條邊框的顏色
  • progress_border_width     進(jìn)度條邊框的寬度

有需要定義其他屬性的,可以進(jìn)行擴(kuò)充下面是效果圖

上代碼

VerticalProgress

public class VerticalProgress extends View {

? ? //進(jìn)度條圓角
? ? private int mRadius;
? ? //進(jìn)度條是否有邊框
? ? private boolean mBorderEnable;
? ? //是否有漸變色
? ? private boolean mGradientEnable;
? ? //漸變色
? ? private int mStartResId;
? ? private int mEndResId;
? ? //邊框的顏色
? ? private int mBorderColorResId;
? ? //進(jìn)度條背景填充色
? ? private int mProgressBgColorId;
? ? //邊框?qū)挾?
? ? private int mBorderWidth;

? ? private int mProgress = 10;
? ? private int max = 100;

? ? private int mWidth;
? ? private int mHeight;

? ? private RectF mRectF;
? ? private Paint mPaint;

? ? public VerticalProgress(Context context) {
? ? ? ? super(context);
? ? ? ? init(context, null);
? ? }

? ? public VerticalProgress(Context context, @Nullable AttributeSet attrs) {
? ? ? ? super(context, attrs);
? ? ? ? init(context, attrs);
? ? }

? ? @Override
? ? protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
? ? ? ? super.onMeasure(widthMeasureSpec, heightMeasureSpec);
? ? ? ? mWidth = getMeasuredWidth() - 1;// 寬度值
? ? ? ? mHeight = getMeasuredHeight() - 1;// 高度值
? ? }

? ? private void init(Context context, AttributeSet attrs) {
? ? ? ? TypedArray typedArray = null;
? ? ? ? if (attrs != null) {
? ? ? ? ? ? typedArray = context.obtainStyledAttributes(attrs, R.styleable.verticalProgress);

? ? ? ? ? ? mRadius = typedArray.getInt(R.styleable.verticalProgress_progress_radius, 0);
? ? ? ? ? ? mBorderEnable = typedArray.getBoolean(R.styleable.verticalProgress_progress_border_enable, false);
? ? ? ? ? ? mGradientEnable = typedArray.getBoolean(R.styleable.verticalProgress_progress_gradient_enable, true);
? ? ? ? ? ? mStartResId = typedArray.getResourceId(R.styleable.verticalProgress_progress_start_color, R.color.colorPrimary);
? ? ? ? ? ? mProgressBgColorId = typedArray.getResourceId(R.styleable.verticalProgress_progress_solid_color, R.color.white);
? ? ? ? ? ? mEndResId = typedArray.getResourceId(R.styleable.verticalProgress_progress_end_color, R.color.color_4EA6FD);
? ? ? ? ? ? mBorderColorResId = typedArray.getResourceId(R.styleable.verticalProgress_progress_border_color, R.color.color_4EA6FD);
? ? ? ? ? ? mBorderWidth = typedArray.getResourceId(R.styleable.verticalProgress_progress_border_width, 10);
? ? ? ? }

? ? ? ? if (typedArray != null) {
? ? ? ? ? ? typedArray.recycle();
? ? ? ? }

? ? ? ? mRectF = new RectF();
? ? ? ? mPaint = new Paint();
? ? ? ? mPaint.setAntiAlias(true);
? ? }

? ? @SuppressLint("DrawAllocation")
? ? @Override
? ? protected void onDraw(Canvas canvas) {
? ? ? ? super.onDraw(canvas);
? ? ? ? if (mRadius == 0) {
? ? ? ? ? ? //弧度為高度的一半
? ? ? ? ? ? mRadius = mWidth / 2;
? ? ? ? }

? ? ? ? if (mBorderEnable) {
? ? ? ? ? ? //第一層矩形(描邊層)
? ? ? ? ? ? mRectF.set(0, 0, mWidth, mHeight);
? ? ? ? ? ? //第一層矩形顏色(進(jìn)度條描邊的顏色)
? ? ? ? ? ? mPaint.setColor(getResources().getColor(mBorderColorResId));
? ? ? ? ? ? //畫第一層圓角矩形
? ? ? ? ? ? canvas.drawRoundRect(mRectF, mRadius, mRadius, mPaint);
? ? ? ? ? ? //第二層矩形顏色(背景層顏色)
? ? ? ? ? ? mPaint.setColor(getResources().getColor(mProgressBgColorId));
? ? ? ? ? ? //第二層矩形(背景層)
? ? ? ? ? ? mRectF.set(mBorderWidth, mBorderWidth, mWidth - mBorderWidth, mHeight - mBorderWidth);
? ? ? ? ? ? //畫背景層圓角矩形(蓋在描邊層之上)
? ? ? ? ? ? canvas.drawRoundRect(mRectF, mRadius, mRadius, mPaint);
? ? ? ? }

? ? ? ? if (mProgress == 0)//進(jìn)度為 0不畫進(jìn)度
? ? ? ? ? ? return;

? ? ? ? float section = mProgress / max;

? ? ? ? //進(jìn)度層底層
? ? ? ? mRectF.set(+8, mHeight - mProgress / 100f * mHeight + 10, mWidth - 8, mHeight - 8);

? ? ? ? if (mGradientEnable) {
? ? ? ? ? ? //漸變器
? ? ? ? ? ? LinearGradient shader = new LinearGradient(0, 0, mWidth * section, mHeight,
? ? ? ? ? ? ? ? ? ? getResources().getColor(mStartResId), getResources().getColor(mEndResId), Shader.TileMode.CLAMP);

? ? ? ? ? ? //第三層矩形顏色(進(jìn)度漸變色)
? ? ? ? ? ? mPaint.setShader(shader);
? ? ? ? }

? ? ? ? //畫第三層(進(jìn)度層)圓角矩形(蓋在背景層之上)
? ? ? ? canvas.drawRoundRect(mRectF, mRadius, mRadius, mPaint);

? ? ? ? //清除之前傳遞的shader
? ? ? ? mPaint.setShader(null);
? ? }

? ? public void setProgress(int currentCount) {

? ? ? ? this.mProgress = currentCount > max ? max : currentCount;

? ? ? ? postInvalidate();

? ? }
}

attr.xml樣式

<declare-styleable name="verticalProgress">
? ? ? ? <attr name="progress_radius" format="dimension" />
? ? ? ? <attr name="progress_border_width" format="dimension" />
? ? ? ? <attr name="progress_gradient_enable" format="boolean" />
? ? ? ? <attr name="progress_border_enable" format="boolean" />
? ? ? ? <attr name="progress_start_color" format="color" />
? ? ? ? <attr name="progress_solid_color" format="color" />
? ? ? ? <attr name="progress_end_color" format="color" />
? ? ? ? <attr name="progress_border_color" format="boolean" />
</declare-styleable>

最后調(diào)用示例

<com.widget.VerticalProgress
? ? ? ? ? ? android:id="@+id/vp_progress"
? ? ? ? ? ? android:layout_width="20dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? app:progress_border_enable="true"
? ? ? ? ? ? app:progress_solid_color="@color/white"
? ? ? ? ? ? android:layout_centerInParent="true" />

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

富锦市| 绥芬河市| 凌源市| 大理市| 乌什县| 大渡口区| 海原县| 灵寿县| 抚顺市| 绥芬河市| 方正县| 手游| 栾城县| 桃园县| 乐亭县| 永春县| 响水县| 阜城县| 库尔勒市| 化德县| 大港区| 板桥市| 原阳县| 金乡县| 汤阴县| 莱阳市| 响水县| 稻城县| 卢氏县| 比如县| 巢湖市| 扎鲁特旗| 获嘉县| 镇巴县| 西峡县| 右玉县| 漯河市| 易门县| 明光市| 精河县| 东至县|