anastr / SpeedView

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

How to customize tick number? #204

Closed chanben2005 closed 3 years ago

chanben2005 commented 3 years ago

As shown in illustration. I want the blue range is 10 to 15, green range is 15 to 30, red range is 30 to 50. 111

another, can set short or long of indicator? I just find the "app:sv_indicatorWidth". 333

Thank you!

anastr commented 3 years ago

You can use this simple math to calculate the percent of end point for your section:

endSection = (speedValueAtEnd - minSpeed) / (maxSpeed - minSpeed)

For your values:

val endSection1 = (15 - 10) / (50 - 10)
// So this is your first section
val section1 = Section(0f, endSection1, Color.BLUE)
// For second section
val endSection2 = (30 - 10) / (50 - 10)
val section2 = Section(endSection1, endSection2, Color.GREEN)
val section3 = Section(endSection2, 1f, Color.RED)

speedometer.addSections(section1, section2, section3)

Then you need custom ticks, something like this:

speedometer.ticks = arrayListOf(0f, endSection1, endSection2, 1f)

For indicator you will need to build a custom indicator or use ImageIndicator.

chanben2005 commented 3 years ago

I am follow to try, but tick can't fix the specified position. 444

anastr commented 3 years ago

The value 30 is the middle of your range (10 to 50) that's why it shows in middle. However, if you want to use different visual values I suggest you to do this:

chanben2005 commented 3 years ago

Thank you for your guidance. I will try it.