Thiha Zaw Thiha Zaw - 3 months ago 59
Android Question

Android SeekBar with separators

I am making a custom SeekBar as following image.

Custom SeekBar with separator

after searching through internet, I couldn't find the best solution to meet for this issue. The following code is normal SeekBar control and please help me to change like above image.

<SeekBar
android:id="@+id/seekBar"
android:layout_width="fill_parent"
android:layout_height="@dimen/sbumit_form_field_height"
android:layout_marginTop="@dimen/sbumit_form_field_top_mergin"
android:layout_marginLeft="@dimen/sbumit_form_field_side_mergin"
android:layout_marginRight="@dimen/sbumit_form_field_side_mergin"
android:max="6"/>

Answer

Your image shows exactly this library (my fork). If You are not allowed to use it You can at least check solution and write Your own code.

Check ComboSeekbar onDraw method. Check forked ComboSeekbar onDraw method.

Usage example:

  1. Open your project build.gradle (root folder) and add:

    allprojects {
        repositories {
            maven { url "http://dl.bintray.com/arnoult-antoine/maven/" }
            ...
        }
    }
    
  2. In app main module (probably "app" directory) build.gradle file for compile library add:

    dependencies {
        ...
        compile 'com.aat:android-comboseekbar:1.0.2@aar'
    }
    
  3. Go to your XML layout file and put:

    <com.infteh.comboseekbar.ComboSeekBar 
        xmlns:cbs="http://schemas.android.com/apk/res-auto"
        android:id="@+id/comboseekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        cbs:myColor="@android:color/black"
        cbs:textSize="16sp" />
    
  4. In Activity onCreate init it with for example this code:

    ComboSeekBar comboSeekBar = (ComboSeekBar) findViewById(R.id.comboseekbar);
    List<String> points = new ArrayList<>();
    points.add("Point 1");
    points.add("Point 2");
    points.add("Point 3");
    points.add("Point 4");
    comboSeekBar.setAdapter(points);
    
  5. Enjoy your Combo Seekbar:

enter image description here

Comments