Skip to content

abd3lraouf/FancyAndroidRuler

Repository files navigation

Fancy android ruler

Hits API ktlint

Ruler in action

This image is from one of my currently under-development apps

RTL Support

Length

LTR Support by default

enter image description here

Usage

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        //...
        mavenCentral()
    }
}

Step 2. Add the dependency:

Release Snapshot

dependencies {
        implementation 'abd3lraouf.dev.ruler:android:<VERSION>'
}

Usage

XML

    <TextView
        android:id="@+id/value_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textSize="32sp"
        tools:text="1" />

    <dev.abd3lraouf.custom.ruler.FancyRuler
        android:id="@+id/myScrollingValuePicker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:rulerMinValue="15"
        app:rulerMaxValue="108"
        app:rulerDefaultPosition="107.75"
        app:rulerSystem="imperial"
        app:rulerPointerColor="#FF0000FF"
        app:rulerNormalUnitBarColor="#FF0000FF"
        app:rulerMiddleUnitBarColor="#00BCD4"
        app:rulerMiddleUnitTextColor="#00BCD4"
        app:rulerQuarterUnitBarColor="#E91E63"
        app:rulerQuarterUnitTextColor="#E91E63"
        app:rulerThreeQuartersUnitBarColor="#FFEB3B"
        app:rulerThreeQuartersUnitTextColor="#FFEB3B"
        app:rulerMainUnitBarColor="#4CAF50"
        app:rulerMainUnitTextColor="#4CAF50"
        app:rulerBackgroundColor="#000"
        />

Kotlin

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        myScrollingValuePicker.setOnScrollChangedListener({
            value_text.text = myScrollingValuePicker.getReading(it).toString()
        }, 250)
    }
}

All available themes

RTL Support

RTL

LTR Support by default

LTR