public class TextProgressbarextends LinearLayout {
public FlashTextViewtvThumb;
//public TextView tvThumb;
public ProgressBarseekBar;
public RelativeLayoutrelative_circle;
private ImageViewivCircle;
private int width =0;
private Handlerhandler;
private int progress;//進(jìn)度
private int color01=0xffffffFF;
private int color02=0x33FFED71;
private int color03=0xffffffFF;
private int[]colors=new int[] {color01, color02,color03};
public TextProgressbar(Context context) {
super(context);
init();
}
public TextProgressbar(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
LayoutInflater.from(getContext()).inflate(R.layout.view_thumb_text_seekbar, this);
setOrientation(LinearLayout.VERTICAL);
//tvThumb = (TextView) findViewById(R.id.tvThumb);
tvThumb = (FlashTextView) findViewById(R.id.tvThumb);
tvThumb.setmAnimating(true);
tvThumb.setColors(colors);
seekBar = (ProgressBar) findViewById(R.id.sbProgress);
relative_circle = (RelativeLayout) findViewById(R.id.relative_circle);
ivCircle = (ImageView) findViewById(R.id.iv_circle);
handler =new Handler();
}
public void setCircleBackground(Drawable drawable) {
ivCircle.setBackground(drawable);
}
public void setProgressTextColor(int color) {
tvThumb.setTextColor(color);
}
public void setProgressDrawable(Drawable drawable) {
seekBar.setProgressDrawable(drawable);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
width = MeasureSpec.getSize(widthMeasureSpec);
upDateProgress();
}
/**
* 設(shè)置Thumb的文字
*
* @param text
*/
public void setThumbText(String text) {
tvThumb.setText(text);
}
/**
* 設(shè)置進(jìn)度
*
* @param progress
*/
public void setProgress(int progress) {
seekBar.setProgress(progress);
upDateProgress();
}
/**
* 設(shè)置進(jìn)度百分比
*
* @param num 0-100
*/
public void setProgress(int num, boolean isAnim) {
if (isAnim) {
if (num >=100) {
num =100;
}else if (num <=0) {
num =0;
}
final int finalNum = num;
new Thread(new Runnable() {
@Override
public void run() {
for (int i =0; i <=finalNum; i++) {
progress = i;
try {
Thread.sleep(30);
handler.post(new Runnable() {
@Override
public void run() {
seekBar.setProgress(progress);
upDateProgress();
}
});
}catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}else {
seekBar.setProgress(num);
upDateProgress();
}
}
private void upDateProgress() {
String content =tvThumb.getText().toString();
float contentWidth =tvThumb.getPaint().measureText(content) /2 +70;
int realWidth =width -seekBar.getPaddingLeft()-seekBar.getPaddingRight();
// int maxLimit = (int) (width - contentWidth - seekBar.getPaddingRight());
// int minLimit = seekBar.getPaddingLeft();
float percent = (float) (1.0 *seekBar.getProgress() /seekBar.getMax());
// int left = minLimit + (int) (realWidth * percent - contentWidth / 2.0);
// left = left <= minLimit ? minLimit : left >= maxLimit ? maxLimit : left;
float progressWidth = realWidth * percent +seekBar.getPaddingLeft();
int left = (int) (progressWidth -10);
if (left <0) left =0;
if (left > realWidth - contentWidth) left = (int) (realWidth - contentWidth);
tvThumb.setPadding(left, 0, 0, 0);
int circle = (int) (progressWidth - UIUtil.dip2px(4.5f));
if ((circle + UIUtil.dip2px(8)) >width) {
relative_circle.setPadding(circle - UIUtil.dip2px(0), 0, 0, 0);
}else {
relative_circle.setPadding(circle, 0, 0, 0);
}
}
}
文字跟隨的進(jìn)度條
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門倔监,熙熙樓的掌柜王于貴愁眉苦臉地迎上來直砂,“玉大人,你說我怎么就攤上這事浩习【苍荩” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵瘦锹,是天一觀的道長籍嘹。 經(jīng)常有香客問我闪盔,道長弯院,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任泪掀,我火速辦了婚禮听绳,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘异赫。我一直安慰自己椅挣,他們只是感情好头岔,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著鼠证,像睡著了一般峡竣。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上量九,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼川队!你這毒婦竟也來了力细?” 一聲冷哼從身側(cè)響起,我...
- 序言:老撾萬榮一對情侶失蹤固额,失蹤者是張志新(化名)和其女友劉穎艳汽,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體对雪,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡河狐,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了瑟捣。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片馋艺。...
- 正文 年R本政府宣布踱蛀,位于F島的核電站,受9級特大地震影響贵白,放射性物質(zhì)發(fā)生泄漏率拒。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一禁荒、第九天 我趴在偏房一處隱蔽的房頂上張望猬膨。 院中可真熱鬧,春花似錦呛伴、人聲如沸勃痴。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽沛申。三九已至劣领,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間铁材,已是汗流浹背剖踊。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長得像固惯,于是被迫代替她去往敵國和親梆造。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- CircleProgress 項(xiàng)目中要用到進(jìn)度百分比跟隨進(jìn)度動(dòng)的效果贴捡,在網(wǎng)上找了一下忽肛,沒找到合適的,就自己寫了一個(gè)...
- 成長記錄-連載(三十六) ——我的第一篇五千字長文罕模,說了什么,你一定想不到 并不是不想每天寫公眾號帘瞭,而是之前思考怎...
- 實(shí)在不知道起什么名字好了淑掌,哈哈〉睿看看效果先抛腕。 其實(shí)時(shí)很簡單的一個(gè)效果,但是我剛看到的時(shí)候媒殉,哇担敌!好神奇,怎么實(shí)現(xiàn)的啊...
- 看了簡書熱門的文章《致20歲售貌,糟糕的自己》,我猛然驚醒疫萤。作者給我的感覺似曾相識颂跨,想了半天,那不就是我自己嗎扯饶? 我今...