android 进度框架,Android中github开源进度条类框架SmoothProgressBar的使用

本文详细介绍了如何在Android Studio项目中集成SmoothProgressBar开源库,包括在build.gradle文件中添加依赖、配置样式、添加颜色资源和字符串资源,以及在布局文件和Java代码中使用SmoothProgressBar的方法。适合Android开发者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

66b52468c121889b900d4956032f1009.png

8种机械键盘轴体对比

本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?

前言

SmoothProgressBar是Github上的一个开源框架, 牛人所著, 只作翻译;

开发环境:Android studio;Eclipse用户请直接进入项目首页,克隆源码。

4cdb7d541291751fba4a2f369d2a8277.png

详细配置使用说明

Maven 库添加

作者已经将该库放在Maven Centra中了, 所以Android Studio 用户可直接进行如下配置:在“项目(project)”的build.gradle中添加如下代码:1

2

3

4

5repositories {

maven {

url "https://oss.sonatype.org/content/repositories/snapshots/"

}

}

在app文件夹的build.gradle文件中添加如下代码:1

2

3dependencies {

compile 'com.github.castorflex.smoothprogressbar:library:[email protected]'

}

加入一些作者提供的Style吧

在res/values/styles.xml文件中添加样式:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

@style/SmoothProgressBar

12dp

4

0.7

spb_interpolator_linear

@array/gplus_colors

8dp

2

1.7

2

3.4

spb_interpolator_acceleratedecelerate

true

true

@array/gplus_colors

true

false

0dp

3

2.0

@android:anim/decelerate_interpolator

@array/gplus_colors

true

4dp

4

1

@anim/pocket_interpolator

@array/pocket_bar_colors

true

false

添加缺少的颜色资源

在res/values/color.xml添加如下代码:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

@color/holo_blue_dark

@color/holo_yellow_dark

@color/holo_green_dark

@color/holo_purple_dark

@color/holo_red_dark

@color/gplus_color_1

@color/gplus_color_2

@color/gplus_color_3

@color/gplus_color_4

@color/pocket_color_1

@color/pocket_color_1

@color/pocket_color_1

@color/pocket_color_1

@color/pocket_color_2

@color/pocket_color_2

@color/pocket_color_2

@color/pocket_color_2

@color/pocket_color_3

@color/pocket_color_3

@color/pocket_color_3

@color/pocket_color_3

@color/pocket_color_4

@color/pocket_color_4

@color/pocket_color_4

@color/pocket_color_4

@color/pocket_color_1

@color/pocket_color_2

@color/pocket_color_3

@color/pocket_color_4

#85edb9

#34bdb7

#ee4458

#fcb74d

#3e802f

#f4b400

#427fed

#b23424

#0099cc

#ff8800

#669900

#9933cc

#cc0000

添加缺少的strings

在res/values/strings.xml添加如下代码:1

2

3

4

5

6

Accelerate

Linear

AccelerateDecelerate

Decelerate

还有一个动画资源:anim

在res/anim文件夹下新建一个名为:pocket_interpolator.xml动画资源文件,并添加如下代码:1

2

3

4<?xml version="1.0" encoding="utf-8"?>

android:factor="1.8"

xmlns:android="http://schemas.android.com/apk/res/android" />

这样所需要使用的资源都添加完毕了

SmoothProgressBar调用

提供两种方式: <1> 在布局文件中添加直接使用; <2> 代码调用

<1> 在布局文件中添加直接使用:

在xml文件中直接添加布局代码使用, 添加代码如下:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:indeterminate="true"

app:spb_sections_count="4"

app:spb_color="#FF0000"

app:spb_speed="2.0"

app:spb_stroke_width="4dp"

app:spb_stroke_separator_length="4dp"

app:spb_reversed="false"

app:spb_mirror_mode="false"

app:spb_progressiveStart_activated="true"

app:spb_progressiveStart_speed="1.5"

app:spb_progressiveStop_speed="3.4" />

<2> 使用java代码控制实现,灵活(推荐)

先在布局文件中定义个id:1

2

3

4

5

6

android:id="@+id/smooth_progress_bar"

android:layout_width="match_parent"

android:layout_height="8dp"

style="@style/GNowProgressBar"

android:indeterminate="true" />

在相应的Activity中实现绑定:1

2

3

4

5

6

7

8

9

10// 变量声明

private SmoothProgressBar progressBar;

// 在void onCreate(Bundle savedInstanceState)绑定id

progressBar = (SmoothProgressBar)findViewById(R.id.smooth_progress_bar);

// 由于已经定义加载布局时,进度条就会自动运行(同方法一)

// 使用progressiveStop()在合适的地方停止进度条运行

// 如网络通信结束,登陆成功,webview页面加载完毕等时刻停止

progressBar.progressiveStop();

a2526eff4e1d518dbfb56de82abe724e.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值