Search code examples
androidandroid-layoutseekbar

How to make a circular seek bar with an image fit to its circle in android


I want to make a circular seek bar with an image fit to its circle for my application , I have used this link https://github.com/devadvance/circularseekbar for making a circular seek bar ,It is working good but I am not able to set an image fit to its circle that i required in my application. Here is the image that i want to set fit to the circleenter image description here

and circular seek bar to which this image I have to set.Is there anyone who can help me in this Thanks in advance.

enter image description here


Solution

  • I'm writing another answer as it's too long for a comment.

    View.post(new Runnable()); this way the action inside the Runnable will be triggered when the View is on the screen, it has it's final Width and Height.

    You can get the actual width and height of the seek bar and give this width and height to the ImageView.

    convertDpToPixel method Convers a dp value to actual device pixels. You can experiment with the (int dp) value. You should give the ImageView a little smaller values so that it'll be inside the SeekBar

        final CircularSeekBar circularSeekBar = new CircularSeekBar(getActivity());
        final ImageView imageView = new ImageView(getActivity());
        final int dp = (int) Utilities.convertDpToPixel(5, getActivity());
        circularSeekBar.post(new Runnable() {
            @Override
            public void run() {
                imageView.setLayoutParams(new RelativeLayout.LayoutParams(circularSeekBar.getWidth() - dp,
                        circularSeekBar.getHeight() - dp));
            }
        });