1

GitHub has the exelent sample with 1300 stars how to customise seekbar, but there aren't way to rotate it from horizontly to verticaly...

when i try to add

android:rotation="-90"

it is crazy rotate, but it still take a space like horizontal seekbar .

Next step i have tryed overide the seekbar :

public class VerticalDiscreteSeekBar extends DiscreteSeekBar {
public VerticalDiscreteSeekBar(Context context) {
    super(context);
}

public VerticalDiscreteSeekBar(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public VerticalDiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(h, w, oldh, oldw);
}

@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(heightMeasureSpec, widthMeasureSpec);
    setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}

protected void onDraw(Canvas c) {
    c.rotate(-90);
    c.translate(-getHeight(), 0);

    super.onDraw(c);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!isEnabled()) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_UP:
            setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
            onSizeChanged(getWidth(), getHeight(), 0, 0);

            break;

        case MotionEvent.ACTION_CANCEL:
            break;
    }
    return true;
}
}

XML is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".tools.TestDeleteIt">

<com.example.android.camera2basic.tools.VerticalDiscreteSeekBar
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:dsb_thumbColor="@color/color_white"
    app:dsb_indicatorColor="@color/color_white"
    app:dsb_indicatorFormatter="%03d"
      app:dsb_indicatorTextAppearance="@style/CustomFloaterTextAppearance"
    app:dsb_max="14"
    app:dsb_min="-14"
    app:dsb_progressColor="@color/ntz_color_yellow"
    app:dsb_rippleColor="@color/ntz_color_yellow"
    app:dsb_scrubberHeight="10dp"
    app:dsb_thumbSize="25dp"
    app:dsb_trackColor="@color/ntz_color_yellow"
    app:dsb_trackHeight="10dip"/>
</LinearLayout>

eventualy it is looks so (it is show just shape, but without real view)

введите сюда описание изображения

What am i doing wrong? How i can make it working?

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • Have you seen the vertical seekbar library on [Github](https://github.com/h6ah4i/android-verticalseekbar/) ? – x0r May 15 '16 at 19:48
  • @R.Kirill yes i have seen this one, but i like my sample because it have a lot of custom properties... – Sirop4ik May 15 '16 at 19:57
  • I didn't get why you translate the canvas can you explain it ? maybe it has something todo with the drawing section – Omar May 15 '16 at 20:02
  • @Omar i found explain from another person from stack here http://stackoverflow.com/questions/3333658/how-to-make-a-vertical-seekbar-in-android and try to use it... Do you have any suggestions? – Sirop4ik May 15 '16 at 20:30

0 Answers0