Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_flowbox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_flowbox
Commits
a3de034a
Commit
a3de034a
authored
Jul 07, 2021
by
mengcuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加百分比按时间内规定变化
parent
b88d4e35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
+91
-0
NumAnimUtil.java
...c/main/java/com/mints/flowbox/ui/widgets/NumAnimUtil.java
+91
-0
No files found.
app/src/main/java/com/mints/flowbox/ui/widgets/NumAnimUtil.java
0 → 100644
View file @
a3de034a
package
com
.
mints
.
flowbox
.
ui
.
widgets
;
import
android.widget.TextView
;
import
java.util.LinkedList
;
import
java.util.Random
;
/**
* 描述:
* 作者:孟崔广
* 时间:2021/7/7 15:20
*/
public
class
NumAnimUtil
{
//每秒刷新多少次
private
static
final
int
COUNTPERS
=
100
;
public
static
void
startAnim
(
TextView
textV
,
float
num
)
{
startAnim
(
textV
,
num
,
2000
);
}
public
static
void
startAnim
(
TextView
textV
,
float
num
,
long
time
)
{
if
(
num
==
0
)
{
textV
.
setText
(
NumAnimUtil
.
NumberFormat
(
num
,
2
));
return
;
}
Float
[]
nums
=
splitnum
(
num
,
(
int
)
((
time
/
1000
f
)
*
COUNTPERS
));
Counter
counter
=
new
Counter
(
textV
,
nums
,
time
);
textV
.
removeCallbacks
(
counter
);
textV
.
post
(
counter
);
}
private
static
Float
[]
splitnum
(
float
num
,
int
count
)
{
Random
random
=
new
Random
();
float
numtemp
=
num
;
float
sum
=
0
;
LinkedList
<
Float
>
nums
=
new
LinkedList
<
Float
>();
nums
.
add
(
0
f
);
while
(
true
)
{
float
nextFloat
=
NumAnimUtil
.
NumberFormatFloat
(
(
random
.
nextFloat
()
*
num
*
2
f
)
/
(
float
)
count
,
2
);
System
.
out
.
println
(
"next:"
+
nextFloat
);
if
(
numtemp
-
nextFloat
>=
0
)
{
sum
=
NumAnimUtil
.
NumberFormatFloat
(
sum
+
nextFloat
,
2
);
nums
.
add
(
sum
);
numtemp
-=
nextFloat
;
}
else
{
nums
.
add
(
num
);
return
nums
.
toArray
(
new
Float
[
0
]);
}
}
}
static
class
Counter
implements
Runnable
{
private
final
TextView
view
;
private
Float
[]
nums
;
private
long
pertime
;
private
int
i
=
0
;
Counter
(
TextView
view
,
Float
[]
nums
,
long
time
)
{
this
.
view
=
view
;
this
.
nums
=
nums
;
this
.
pertime
=
time
/
nums
.
length
;
}
@Override
public
void
run
()
{
if
(
i
>
nums
.
length
-
1
)
{
view
.
removeCallbacks
(
Counter
.
this
);
return
;
}
view
.
setText
(
NumAnimUtil
.
NumberFormat
(
nums
[
i
++],
2
));
view
.
removeCallbacks
(
Counter
.
this
);
view
.
postDelayed
(
Counter
.
this
,
pertime
);
}
}
public
static
String
NumberFormat
(
float
f
,
int
m
)
{
return
String
.
format
(
"%."
+
m
+
"f"
,
f
);
}
public
static
float
NumberFormatFloat
(
float
f
,
int
m
)
{
String
strfloat
=
NumberFormat
(
f
,
m
);
return
Float
.
parseFloat
(
strfloat
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment