Android: Change slider step size based on range
Credit to JosJuice for the slider formula
This commit is contained in:
parent
e70b57fe8a
commit
937e08980e
|
@ -286,7 +286,18 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
|
|||
slider.setValueFrom(item.getMin());
|
||||
slider.setValueTo(item.getMax());
|
||||
slider.setValue(mSeekbarProgress);
|
||||
slider.setStepSize(1);
|
||||
|
||||
// Sliders can get frustrating to use with a small step size and large ranges
|
||||
int maxRange = item.getMax();
|
||||
if (maxRange <= 100)
|
||||
{
|
||||
slider.setStepSize(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
slider.setStepSize((int) Math.pow(10, Math.ceil(Math.log10(maxRange)) - 2));
|
||||
}
|
||||
|
||||
slider.addOnChangeListener(this);
|
||||
|
||||
mDialog = new MaterialAlertDialogBuilder(mView.getActivity())
|
||||
|
|
Loading…
Reference in New Issue