anastr / SpeedView

Dynamic Speedometer and Gauge for Android. amazing, powerful, and multi shape :zap:
Apache License 2.0
1.29k stars 324 forks source link

Set dynamic values to section #205

Closed abby1602 closed 3 years ago

abby1602 commented 3 years ago

I have to set the value dynamically from json to speedview

For example i am getting the value for green orange red as 65 , 95, 100 .

Then how to set the sections accordingly

I am getting the values from json so it will change accordingly.

PLease help me out in this

anastr commented 3 years ago

First you need to clear previous sections:

speedometer.clearSections()

Then add new ones:

val firstSectionEndPoint = .65f // Get from json.
val secondSectionEndPoint = .95f
val thirdSectionEndPoint = 1f
speedometer.addSections(
        Section(0f, firstSectionEndPoint , Color.GREEN),
        Section(firstSectionEndPoint, secondSectionEndPoint, Color.ORANGE),
        Section(secondSectionEndPoint, thirdSectionEndPoint, Color.RED)
)

Don't try to edit your existing sections, it may leads to conflict exception.