您的位置:首页 > 移动开发 > Android开发

progressblock 安卓自定义进度条 progressbar 高仿仿QQ下载进度条

2016-03-20 22:00 671 查看

progressblock 安卓自定义进度条 progressbar 高仿仿QQ下载进度条

附上我在公司做下载播放项目



主要使用方法

progressBlock = (ProgressBlock) findViewById(R.id.progressblock);
progressBlock.setMaxProgress(count);//最大值可以超过100的,进度只要传递对了进行,会进行换算的

case R.id.btn_switch_orientation:
progressBlock.setDirection(progressBlock.getDirection()==LinearLayout.HORIZONTAL?LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
break;
case R.id.btn_switch_reverse://反转就是 比如方向是垂直方向那么是从上到下,反正开启则是从下到上,而是水平方向反转为真则是从右到左
progressBlock.setReverse(!progressBlock.isReverse());
break;
case R.id.btn_switch_text_color://设置百分比字体颜色
progressBlock.setProgressTextColor(v.getTag()==null?Color.GREEN:Color.RED);
v.setTag(v.getTag()==null?"":null);
break;
case R.id.btn_switch_text_orientation:
TextView tv= progressBlock.getProgressTextView();
tv.setGravity(tv.getGravity()==Gravity.CENTER?Gravity.TOP:(tv.getGravity()==Gravity.TOP?Gravity.BOTTOM:Gravity.CENTER));
break;
case R.id.btn_switch_block_color://设置进度块颜色,要半透明哦 所以这里是rgba的填写
if(blockflag==0){
progressBlock.setProgressBlockColor(Color.parseColor("#50ff0000"));
blockflag=1;
}else if(blockflag==1){
progressBlock.setProgressBlockColor(Color.parseColor("#5000ff00"));
blockflag=2;
}else {
blockflag=0;
progressBlock.setProgressBlockColor(Color.parseColor("#500000ff"));
}
break;
case R.id.btn_switch_text_size://设置进度文本百分比的文本字体大小
tv= progressBlock.getProgressTextView();
if(block_text_size==0){
tv.setTextSize(10);
block_text_size=1;
}else if(block_text_size==1){
tv.setTextSize(30);
block_text_size=2;
}else {
block_text_size=0;
tv.setTextSize(50);
}


本进度块就是通过就是设置margin实现的不依赖任何第三方库,超级简单实用。

public void setProgress(int progress){
if(getDirection()==LinearLayout.HORIZONTAL){
int margin= (int) ((mWidth/(float)mMaxProgress)*progress);
Log.i(TAG,"marginLeft:"+margin+","+mWidth+"progress:"+progress+",maxProgess:"+mMaxProgress);
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
if(isReverse()){
layoutParams.rightMargin=margin;//从右到左边
}else{
layoutParams.leftMargin=margin;//从左边到右边
}
mViewProgress.setLayoutParams(layoutParams);
if(mtextView.getVisibility()==View.VISIBLE){
int  baifenbi= (int)((progress/(float)mMaxProgress)*100);
mtextView.setText((baifenbi)+"%");
}
}else if(getDirection()==LinearLayout.VERTICAL){
int margin= (int) ((mHeight/(float)mMaxProgress)*progress);
Log.i(TAG,"marginLeft:"+margin+","+mHeight+"progress:"+progress+",maxProgess:"+mMaxProgress);
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
if(isReverse()){
layoutParams.bottomMargin=margin;//从下到上
}else{
layoutParams.topMargin =margin;//从上到下
}
mViewProgress.setLayoutParams(layoutParams);
if(mtextView.getVisibility()==View.VISIBLE){
int  baifenbi= (int)((progress/(float)mMaxProgress)*100);
mtextView.setText((baifenbi)+"%");
}
}
}
需要用的的就是一个简单的公式了。
//传递的值
int margin= (int) ((mWidth/(float)mMaxProgress)*progress);
//转换成百分比
int  baifenbi= (int)((progress/(float)mMaxProgress)*100);


联系我共同交流共同进步,图片在下面啦,比较大会截图的可以教教我怎么弄gif,又不影响质量 又速度快哈.

github下载地址

https://github.com/qssq/Progress-block-Progress-Bar-qq

as可以直接用:

compile ‘space.qssq:progressblock:0.1’

<RelativeLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:background="#0f0"
android:gravity="center"
>

<ImageView

android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/img_girl"
/>

<space.qssq.progressblock.ProgressBlock
android:id="@+id/progressblock"

android:layout_width="match_parent"
android:layout_height="match_parent"
></space.qssq.progressblock.ProgressBlock>

</RelativeLayout>



QQ35068264

网站http://qssq666.cn

http://github.com/qssq
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android