Android開源:CProgressButton -仿 iOS 的下載按鈕

biaoaction 7年前發布 | 6K 次閱讀 安卓開發 Android開發 移動開發

CProgressButton

a circle progress button like iOS

Usage:

code

final CProgressButton progressButton = (CProgressButton)findViewById(R.id.btn);
        progressButton.setbgDrawable(R.drawable.bounder,40); //config  bg
        progressButton.setStroke(1,R.color.colorAccent);  //config stroke color
        final TextView tv = (TextView) findViewById(R.id.state);
        progressButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ValueAnimator valueAnimator = ValueAnimator.ofInt(0,100);
                if(progressButton.getState() == CProgressButton.STATE.NORMAL){
                    progressButton.setState(CProgressButton.STATE.PROGRESS);
                    valueAnimator.setDuration(5000);
                    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            int value = (int)animation.getAnimatedValue();
                            tv.setText("state progress:"+value);
                            if(value == 100){
                                progressButton.setState(CProgressButton.STATE.NORMAL);
                                tv.setText("state normal");
                                progressButton.setText("Finish");
                            }
                            progressButton.setProgress(value);
                        }
                    });
                    valueAnimator.start();
                }else{
                    valueAnimator.cancel();
                    progressButton.setState(CProgressButton.STATE.NORMAL);
                    tv.setText("state normal");
                    progressButton.setText("Continue");
                }

        }
    });</code></pre> 

layout

<com.jiang.android.cprogressbutton.CProgressButton
        android:layout_width="65dp"
        android:layout_marginLeft="50dp"
        android:text="Download"
        android:gravity="center"
        android:textSize="12sp"
        android:textColor="@color/colorAccent"
        android:id="@+id/btn"
        android:layout_height="30dp" />

License

Copyright 2016 NewTab

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.</code></pre>

 

 

 

 本文由用戶 biaoaction 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!