Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
新增NumberProgressBar
- Loading branch information
Showing
22 changed files
with
277 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#Android UI Libs之NumberProgressBar | ||
*** | ||
#1. 说明 | ||
*** | ||
[NumberProgressBar](https://github.com/daimajia/NumberProgressBar),顾名思义,数字进度条。该库实现了一个漂亮,简洁的数字进度条。 | ||
|
||
#2. 配置 | ||
*** | ||
在模块的build.gradle上面添加依赖 | ||
``` | ||
dependencies { | ||
compile 'com.daimajia.numberprogressbar:library:1.2@aar' | ||
} | ||
``` | ||
|
||
#3. 基本使用 | ||
*** | ||
##1. 最简单的使用 | ||
*** | ||
- 在xml布局文件中定义`NumberProgressBar`: | ||
``` | ||
<com.daimajia.numberprogressbar.NumberProgressBar | ||
android:id="@+id/number_progress_bar" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"/> | ||
``` | ||
程序显示界面如下: | ||
![](http://i.imgur.com/3JG5dMo.png) | ||
- 在java文件中改变进度条的进度: | ||
``` | ||
setContentView(R.layout.activity_main_number_progress_bar); | ||
this.numberprogressbar = (NumberProgressBar) findViewById(R.id.number_progress_bar); | ||
//设置进度条的进度,参数的值在0-mMax之间取值,mMax默认值是100 | ||
numberprogressbar.setProgress(20); | ||
``` | ||
程序运行界面如下: | ||
![](http://i.imgur.com/57LsUOQ.png) | ||
|
||
##2. 预设样式说明 | ||
*** | ||
`NumberProgressBar`有8这种预设样式: | ||
- NumberProgressBar_Default: 默认的样式 | ||
- NumberProgressBar_Passing_Green | ||
- NumberProgressBar_Relax_Blue | ||
- NumberProgressBar_Grace_Yellow | ||
- NumberProgressBar_Warning_Red | ||
- NumberProgressBar_Funny_Orange | ||
- NumberProgressBar_Beauty_Red | ||
- NumberProgressBar_Twinkle_Night | ||
|
||
这8种预设样式从上到下一次对应这8个进度条: | ||
![](http://i.imgur.com/pf3bgsF.jpg) | ||
|
||
在xml中使用预设样式的简单式例: | ||
``` | ||
<com.daimajia.numberprogressbar.NumberProgressBar | ||
android:id="@+id/number_progress_bar" | ||
style="@style/NumberProgressBar_Default"/> | ||
``` | ||
|
||
##3. 常用属性说明 | ||
*** | ||
`NumberProgressBar`分三块:已到达区域,文本区域,未到达区域: | ||
![](http://i.imgur.com/wxIL31c.jpg) | ||
|
||
- 已到达区域属性: | ||
- `app:progress_reached_color`:已到达区域颜色 | ||
- `app:progress_reached_bar_height`:已到达区域高度 | ||
|
||
- 文本区域属性: | ||
- `app:progress_text_size`:文本字体大小 | ||
- `app:progress_text_color`:文本颜色 | ||
- `app:progress_text_offset`:文本偏移量,是指文本距离已到达区域与未到达区域的距离 | ||
- `app:progress_text_visibility`:文本可见性,默认是可见 | ||
|
||
- 未到达区域: | ||
- `app:progress_unreached_color`:未到达区域颜色 | ||
- `app:progress_unreached_bar_height`:未到达区域高度 | ||
|
||
- 进度条属性: | ||
- `app:max`:进度条的最大进度值 | ||
- `app:progress`:进度条当前进度值 | ||
**注意:`app:max`后来改成了`app:progress_max`,`app:progress`改成了`app:progress_curent`,但是作者没有将最新的库上传到jcenter仓库** | ||
|
||
关于文本区域显示文本的一些说明:文本区域显示文本由三部分组成:前缀,当前进度值,后缀 | ||
- 前缀只能在java文件中设置:`numberprogressbar.setPrefix()`,前缀默认值是空串 | ||
- 当前进度值既可以在xml布局中设置也可以在java文件中设置 | ||
- 后缀只能在java文件中设置:`numberprogressbar.setSuffix()`,后缀默认值是`%` | ||
|
||
|
||
程序源代码下载,我的github仓库:[https://github.com/lavor-zl/UILibs](https://github.com/lavor-zl/UILibs) | ||
|
||
|
||
**欢迎关注我的简书专题:[Android技术漫谈](http://www.jianshu.com/collection/4833a48d1cb2)** | ||
**欢迎关注我的微信公众号:Android技术漫谈** | ||
![](http://i.imgur.com/u75x3BP.jpg) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.lavor.numberprogressbardemo" | ||
minSdkVersion 14 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.4.0' | ||
compile 'com.daimajia.numberprogressbar:library:1.2@aar' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in E:\Android\AndroidSDK/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
...progressbardemo/src/androidTest/java/com/lavor/numberprogressbardemo/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.lavor.numberprogressbardemo; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.lavor.numberprogressbardemo"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
24 changes: 24 additions & 0 deletions
24
numberprogressbardemo/src/main/java/com/lavor/numberprogressbardemo/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.lavor.numberprogressbardemo; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.daimajia.numberprogressbar.NumberProgressBar; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private com.daimajia.numberprogressbar.NumberProgressBar numberprogressbar; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main_number_progress_bar); | ||
this.numberprogressbar = (NumberProgressBar) findViewById(R.id.number_progress_bar); | ||
//设置进度条文本区域显示的前缀 | ||
numberprogressbar.setPrefix(""); | ||
//设置进度条文本区域显示的后缀 | ||
numberprogressbar.setSuffix("%"); | ||
//设置进度条的进度,参数的值在0-mMax之间取值,mMax默认值是100 | ||
numberprogressbar.setProgress(70); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
numberprogressbardemo/src/main/res/layout/activity_main_number_progress_bar.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="com.lavor.numberprogressbardemo.MainActivity"> | ||
|
||
<com.daimajia.numberprogressbar.NumberProgressBar | ||
android:id="@+id/number_progress_bar" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
|
||
app:progress_unreached_color="#CCCCCC" | ||
app:progress_reached_color="#3498DB" | ||
|
||
app:progress_unreached_bar_height="0.75dp" | ||
app:progress_reached_bar_height="1.5dp" | ||
|
||
app:progress_text_size="10sp" | ||
app:progress_text_color="#3498DB" | ||
app:progress_text_offset="1dp" | ||
app:progress_text_visibility="visible" | ||
/> | ||
</RelativeLayout> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">NumberProgressBarDemo</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
15 changes: 15 additions & 0 deletions
15
numberprogressbardemo/src/test/java/com/lavor/numberprogressbardemo/ExampleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.lavor.numberprogressbardemo; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* To work on unit tests, switch the Test Artifact in the Build Variants view. | ||
*/ | ||
public class ExampleUnitTest { | ||
@Test | ||
public void addition_isCorrect() throws Exception { | ||
assertEquals(4, 2 + 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':CircleImageViewDemo', ':android-gif-drawabledemo', ':androidswipelayoutdemo', ':expandablelayoutdemo', ':showcaseviewdemo', ':labelviewdemo', ':android-observablescrollviewdemo', ':androidtreeviewdemo', ':circleindicatordemo', ':android-viewbadgerdemo', ':explosionfielddemo', ':shortcutbadgerdemo', ':brokenviewdemo', ':android-stackblurdemo', ':trianglifydemo', ':shimmer-androiddemo', ':titanicdemo', ':photoviewdemo', ':swipetoloadlayoutdemo', ':discreteseekbardemo' | ||
include ':CircleImageViewDemo', ':android-gif-drawabledemo', ':androidswipelayoutdemo', ':expandablelayoutdemo', ':showcaseviewdemo', ':labelviewdemo', ':android-observablescrollviewdemo', ':androidtreeviewdemo', ':circleindicatordemo', ':android-viewbadgerdemo', ':explosionfielddemo', ':shortcutbadgerdemo', ':brokenviewdemo', ':android-stackblurdemo', ':trianglifydemo', ':shimmer-androiddemo', ':titanicdemo', ':photoviewdemo', ':swipetoloadlayoutdemo', ':discreteseekbardemo', ':numberprogressbardemo' |