第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

activity_main.xml模擬器不顯示?


57936dae0001d76805000343.jpg

57936daf00012ee805000358.jpg

http://img1.sycdn.imooc.com//57936e9b000142c008800495.jpg


package com.view;


import com.example.progressbar.R;


import android.content.Context;

import android.content.res.TypedArray;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.os.Bundle;

import android.support.v4.content.res.TypedArrayUtils;

import android.util.AttributeSet;

import android.util.TypedValue;

import android.widget.ProgressBar;


public class HorPBWithProgress extends ProgressBar {


private static final int DEFAULT_TEXT_SIZE = 10;

private static final int DEFAULT_TEXT_COLOR = 0xFFC00D1;

private static final int DEFAULT_COLOR_UNREACH = 0xffd3d6da;

private static final int DEFAULT_HEIGHT_UNREACH = 2;

private static final int DEFAULT_COLOR_REACH = DEFAULT_TEXT_COLOR;

private static final int DEFAULT_HEIGHT_REACHE = 2;

private static final int DEFAULT_TEXT_OFFSET = 10;


private int mTextSize = sp2px(DEFAULT_TEXT_SIZE);

private int mTextColor = DEFAULT_TEXT_COLOR;

private int mUnReachColor = DEFAULT_COLOR_UNREACH;

private int mUnReachHeight = dp2px(DEFAULT_HEIGHT_UNREACH);

private int mReachColor = dp2px(DEFAULT_COLOR_REACH);

private int mReachHeight = dp2px(DEFAULT_HEIGHT_REACHE);

private int mTextOffset = dp2px(DEFAULT_TEXT_OFFSET);


private Paint mPaint = new Paint();


private int mRealWidth;


public HorPBWithProgress(Context context) {

this(context, null);


}


public HorPBWithProgress(Context context, AttributeSet attrs) {

this(context, attrs, 0);


}


public HorPBWithProgress(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

obtainStyledAttrs(attrs);

}


private void obtainStyledAttrs(AttributeSet attrs) {

// TODO Auto-generated method stub

TypedArray ta = getContext().obtainStyledAttributes(attrs,

R.styleable.HorPBWithProgress);

mTextSize = (int) ta.getDimension(

R.styleable.HorPBWithProgress_progress_text_size, mTextSize);

mTextColor = ta.getColor(

R.styleable.HorPBWithProgress_progress_text_color, mTextColor);

mTextOffset = (int) ta

.getDimension(

R.styleable.HorPBWithProgress_progress_text_offset,

mTextOffset);

mUnReachColor = ta.getColor(

R.styleable.HorPBWithProgress_progress_unreach_color,

mUnReachColor);

mUnReachHeight = (int) ta.getDimension(

R.styleable.HorPBWithProgress_progress_unreach_height,

mUnReachHeight);

mReachHeight = (int) ta.getDimension(

R.styleable.HorPBWithProgress_progress_reach_height,

mReachHeight);

mReachColor = ta

.getColor(R.styleable.HorPBWithProgress_progress_reach_color,

mReachColor);


ta.recycle();

mPaint.setTextSize(mTextSize);

}


@Override

protected synchronized void onMeasure(int widthMeasureSpec,

int heightMeasureSpec) {

// int widthMode = MeasureSpec.getMode(widthMeasureSpec);

int widthVal = MeasureSpec.getSize(widthMeasureSpec);

int height = measureHeight(heightMeasureSpec);

setMeasuredDimension(widthVal, height);

mRealWidth=getMeasuredWidth()-getPaddingLeft()-getPaddingRight();

}


private int measureHeight(int heightMeasureSpec) {

int result=0;

int mode=measureHeight(heightMeasureSpec);

int size=MeasureSpec.getSize(heightMeasureSpec);

if(mode==MeasureSpec.EXACTLY)

{

result=size;

}else

{

int textHeigh=(int) (mPaint.descent()-mPaint.ascent());

result=getPaddingTop()+getPaddingBottom()+Math.max(Math.max(mReachHeight,mUnReachHeight),Math.abs(textHeigh));

if(mode==MeasureSpec.AT_MOST)

{

result=Math.min(result,size);

}

}

return result;

}

@Override

protected synchronized void onDraw(Canvas canvas) {

canvas.save();

canvas.translate(getPaddingLeft(), getHeight()/2);

boolean noNeedUnRech=false;

String text=getProgress()+"%";

int textWidth=(int)mPaint.measureText(text);

float radio=getProgress()*1.0f/getMax();

float progressX=radio*mRealWidth;

if(progressX+textWidth>mRealWidth){

progressX=mRealWidth-textWidth;

noNeedUnRech=true;

}

float endX=progressX-mTextOffset/2;

if(endX>0)

{

mPaint.setColor(mReachColor);

mPaint.setStrokeWidth(mReachHeight);

canvas.drawLine(0, 0, endX, 0, mPaint);

}

mPaint.setColor(mTextColor);

int y=(int) (-(mPaint.descent()+mPaint.ascent())/2);

canvas.drawText(text, progressX, y, mPaint);

if(!noNeedUnRech)

{

float start=progressX+mTextOffset/2+textWidth;

mPaint.setColor(mUnReachColor);

mPaint.setStrokeWidth(mUnReachHeight);

canvas.drawLine(start, 0, mRealWidth, 0, mPaint);

}

canvas.restore();

}

private int dp2px(int dpVal) {

return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,

dpVal, getResources().getDisplayMetrics());

}


private int sp2px(int spVal) {

return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,

spVal, getResources().getDisplayMetrics());


}

}


正在回答

1 回答

你沒(méi)有導(dǎo)入包?HorPBWithProgress,試試點(diǎn)擊進(jìn)度條框,會(huì)有導(dǎo)入提示,選擇第一個(gè)就好了。我androidStdio是這樣的

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Android-打造炫酷進(jìn)度條
  • 參與學(xué)習(xí)       30838    人
  • 解答問(wèn)題       59    個(gè)

Android開(kāi)發(fā)中各種各樣的自定義進(jìn)度條介紹,讓你的APP更炫酷

進(jìn)入課程

activity_main.xml模擬器不顯示?

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)