Sandeep dhiman
Sandeep dhiman

Reputation: 1921

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

Upvotes: 1

Views: 2572

Answers (2)

Lev
Lev

Reputation: 443

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));
        }
    });

Upvotes: 1

Lev
Lev

Reputation: 443

How about putting the circular seek bar at the center in a RelativeLayout.

Put an ImageView to the center of that RelativeLayout too, only a little smaller than the seek bar. Set the src: of the ImageView to your image.

If you can't see the ImageView on runtime, remember to use ImageView.bringToFront();

Upvotes: 0

Related Questions