progressblock 安卓自定義進度條 progressbar 高仿仿QQ下載進度條

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>
  1. imageQQ35068264

  2. 網站http://qssq666.cn

  3. http://github.com/qssq

發佈了31 篇原創文章 · 獲贊 24 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章