在佈局中android
//也能夠設置佈局中的attr屬性 <com.ns.yc.ycprogresslib.CircleProgressbar android:id="@+id/pb_1" android:layout_width="100dp" android:layout_height="100dp" android:text="進度條" />
使用方法git
//設置類型 pb_1.setProgressType(ProgressBarUtils.ProgressType.COUNT); //設置圓形的填充顏色 pb_1.setInCircleColor(getResources().getColor(R.color.redTab)); //設置外部輪廓的顏色 pb_1.setOutLineColor(getResources().getColor(R.color.grayLine)); //設置進度監聽 pb_1.setCountdownProgressListener(1, progressListener); //設置外部輪廓的顏色 pb_1.setOutLineWidth(2); //設置進度條線的寬度 pb_1.setProgressLineWidth(5); //設置進度 pb_1.setProgress(60); //設置倒計時總時間 pb_1.setTimeMillis(3000); //設置進度條顏色 pb_1.setProgressColor(getResources().getColor(R.color.colorPrimary)); //開始 pb_1.start(); //暫停 pb_1.stop(); //從新開始 pb_1.reStart();
在佈局中github
<com.ns.yc.ycprogresslib.NumberProgressbar android:id="@+id/bar1" android:layout_width="match_parent" android:layout_height="wrap_content" /> <com.ns.yc.ycprogresslib.NumberProgressbar android:id="@+id/bar2" android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" app:progress_max="100" app:progress_reached_bar_height="3dp" app:progress_unreached_bar_height="3dp" app:progress_reached_color="@color/colorPrimary" app:progress_unreached_color="@color/gray3" app:progress_text_size="14sp" app:progress_text_color="@color/colorAccent" app:progress_text_visibility="visible"/>
代碼調用面試
bar1 = (NumberProgressbar) findViewById(R.id.bar1); //設置倒計時總時間 bar1.setTimeMillis(10000); //設置最大進度條的值 bar1.setMax(100); //設置進度條文本的顏色 bar1.setProgressTextColor(this.getResources().getColor(R.color.colorAccent)); //設置進度條文本的大小 bar1.setProgressTextSize(ProgressBarUtils.sp2px(this,14)); //設置百分比文字內容是否可見 bar1.setNumberTextVisibility(ProgressBarUtils.NumberTextVisibility.Visible); //設置百分比進度條的高度 bar1.setReachedBarHeight(10); //設置未更新百分比進度條的高度 bar1.setUnreachedBarHeight(10); //設置百分比進度條的顏色 bar1.setReachedBarColor(this.getResources().getColor(R.color.redTab)); //設置未更新百分比進度條的顏色 bar1.setUnreachedBarColor(this.getResources().getColor(R.color.blackText2)); //設置百分比進度條的監聽 bar1.setOnProgressBarListener(new OnNumberProgressListener() { @Override public void onProgressChange(int current, int max) { } }); //開始 bar1.start(); //暫停 bar1.stop();
<com.ns.yc.ycprogresslib.RingProgressBar android:id="@+id/bar_percent" android:layout_width="100dp" android:layout_height="100dp"/>
bar_percent = (RingProgressBar) findViewById(R.id.bar_percent); //設置進度 bar_percent.setProgress(0); //設置更新進度條顏色 bar_percent.setDotColor(this.getResources().getColor(R.color.colorAccent)); //設置未更新部分的進度條顏色 bar_percent.setDotBgColor(this.getResources().getColor(R.color.blackText)); //設置百分比文字顏色 bar_percent.setPercentTextColor(this.getResources().getColor(R.color.blackText1)); //設置百分比文字大小 bar_percent.setPercentTextSize(ProgressBarUtils.dp2px(this,16.0f)); //設置展現的類型 bar_percent.setShowMode(ProgressBarUtils.RingShowMode.SHOW_MODE_PERCENT); //設置單位的文字內容 bar_percent.setUnitText("%"); //設置單位的文字大小 bar_percent.setUnitTextSize(ProgressBarUtils.dp2px(this,16.0f)); //設置單位的文字顏色 bar_percent.setUnitTextColor(this.getResources().getColor(R.color.blackText1));
/** * 驗證進度。 * * @param progress 你要驗證的進度值。 * @return 返回真正的進度值。 */ private int validateProgress(int progress) { if (progress > 100){ progress = 100; } else if (progress < 0){ progress = 0; } return progress; }
/** * 當自定義控件銷燬時,則調用該方法 */ @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); stop(); }
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.