I have developed my own implementation of a snapping seek bar. It automatically creates indicators depending on how it is configured. The seek bar is able to display short texts for each indicator. If an indicator gets tapped, the thumb animates smoothly to the tapped indicator. The thumb can also be slided and after releasing it snaps to the most nearest indicator. The seek bar is very customizable: you can change several colors, drawables or strings for the items you are using.
The usage is very simple. You can put it in your xml or add it programmatically:
From xml:
<com.tobishiba.SnappingSeekBarSample.views.SnappingSeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:progressDrawable="@drawable/seekbar_progress"
app:thumb="@drawable/seekbar_thumb"
app:progressColor="@color/blue"
app:thumbnailColor="@color/blue_light"
app:indicatorColor="@color/white"
app:textIndicatorColor="@color/white"
app:textSize="12dp"
app:indicatorSize="12dp"
app:itemsArrayId="@array/big_indicators_items"/>
From code:
private SnappingSeekBar createSnappingSeekBarProgrammatically() {
final SnappingSeekBar snappingSeekBar = new SnappingSeekBar(this);
snappingSeekBar.setProgressDrawable(R.drawable.seekbar_progress;
snappingSeekBar.setThumbDrawable(R.drawable.seekbar_thumb);
snappingSeekBar.setItems(new String[]{"Wow", "such", "amazing"});
snappingSeekBar.setProgressColor(resources.getColor(R.color.green_darker));
snappingSeekBar.setThumbnailColor(resources.getColor(R.color.yellow_light));
snappingSeekBar.setTextIndicatorColor(resources.getColor(R.color.red_darker));
snappingSeekBar.setIndicatorColor(resources.getColor(R.color.green_light));
snappingSeekBar.setTextSize(14);
snappingSeekBar.setIndicatorSize(14);
snappingSeekBar.setOnItemSelectionListener(this);
return snappingSeekBar;
}
Just check it out on
github or at
Google Play!
Keine Kommentare:
Kommentar veröffentlichen