0

I have custom Seekbar which shows the status of shipping and below it TextView which shows the package's(goods) location.All i want is to move the text automatically along with thumb without touching the Seekbar,i have tried different solutions but no one worked,i don't know if it's possible to do this or not,if anyone can help i will be very thankful to him.

My output

enter image description here

MyCode:

private void setProgress(int statusNum) {
            switch (statusNum) {
                case 1:
                    seekBar.setProgress(1);
                    break;
                case 2:
                    seekBar.setProgress(2);
                    break;
                case 3:
                    seekBar.setProgress(3);
                    break;
                case 4:
                    seekBar.setProgress(4);
                    break;
                case 5:
                    seekBar.setProgress(5);
                    break;
                case 6:
                    seekBar.setProgress(6);
                    break;
                case 7:
                    seekBar.setProgress(7);
                    break;
                case 8:
                    seekBar.setProgress(8);
                    break;

            }
            int seekBarWidth = seekBar.getWidth() - seekBar.getPaddingLeft() - seekBar.getPaddingRight();
            float displacement = seekBarWidth * (seekBar.getProgress() / seekBar.getMax());
            txtStatus.setX(displacement);
        }

EDIT: Added xml

    <com.warkiz.tickseekbar.TickSeekBar
            android:id="@+id/seekbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tsb_ticks_count="8"
            app:tsb_thumb_color="@color/colorAccent"
            app:tsb_thumb_size="12dp"
            app:tsb_show_tick_marks_type="oval"
            app:tsb_tick_marks_color="#33000000"
            app:tsb_tick_marks_size="6dp"
            app:tsb_track_background_color="#1A00C853"
            app:tsb_track_background_size="2dp"
            android:clickable="false"
            app:tsb_progress="1.0"
            app:tsb_min="1"
            app:tsb_max="8"
            app:tsb_track_progress_color="@color/colorGreen"
            app:tsb_track_progress_size="4dp" />

        <TextView
            android:id="@+id/txt_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10sp"
            android:fontFamily="sans-serif-medium"
            android:text="Прийнято"
            android:textColor="@color/colorGreen"
            android:textAlignment="center"
            android:layout_below="@id/seekbar"
            />
Mohammed Qadah
  • 75
  • 1
  • 10

1 Answers1

1

Issue is here:

        txtStatus.setX(displacement);

Don't change the position of view with this method. Instead use standard layout params and edit the margins (in this case marginLeft) and adjust it to achieve your goal.

ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) txtStatus.getLayoutParams();
p.marginLeft = someValue;
txtStatus.requestLayout();
Amin Rezaei
  • 376
  • 2
  • 11