0

I need to create round volume control, which should looks like this sample:

sample http://dmonzon.com/2011/04/16/free-tabletphone-user-interface-professional-set-v-7/

Are there any tutorials or ideas which way is better for things like this?

Sam
  • 1,509
  • 3
  • 19
  • 28
Anton
  • 1
  • 1
  • 1

1 Answers1

1

One easy way is to use a custom view:

  • Create a custom view
  • Draw the button in the custom view
  • Use onTouchEvent
  • In on MotionEvent.ACTION_MOVE call invalidate();
  • In onDraw calulate the angle between your finger and the centre of the button using atan2() function
  • Then use canvas.rotate to make the button follow the finger.

Some examples which may help: Simple custom view and how to set the initial data (e.g. volume): View Inflation and custom views

Rotate bitmap: Android: How to rotate a moving animated sprite based on the coordinates of its destination

onTouchEvent and invalidate: Make certain area of bitmap transparent on touch

How will the custom view comunicate back the volume? If your activity has a public static volume variable then the custom view can set a volume by calling MyActivity.volume = (100/360)*angle, or better your activity could have a public static method setVolume(volume){...} which then can perform some code when volume changed - Within the volume button custom view call MyActivity.setVolume(volume);

Community
  • 1
  • 1
Lumis
  • 21,517
  • 8
  • 63
  • 67