动画方向条/功率计测量仪android

时间:2022-05-08 22:59:33

I at a loss of where to begin with this. I am try to draw a horizontal bar that has a slider moving left to right (similar to what is seen in basketball shootout games for aiming the ball). I would like to be able to control the speed it moves left to right and then stop it on touch or something of that nature.

我不知道从哪里开始。我试图绘制一个水平条,其中有一个从左到右移动的滑块(类似于篮球瞄准球的瞄准球)。我希望能够控制它从左到右移动的速度,然后在触摸时停止它或那种性质的东西。

same idea with a vertical bar increasing and decreasing like a strength meter. Any suggestions would be appreciated. Thanks.

同样的想法,垂直杆像强度计一样增加和减少。任何建议,将不胜感激。谢谢。

1 个解决方案

#1


0  

There is no pre-defined component to do this, but you can do this using a ProgressBar or SeekBar:

没有预定义的组件可以执行此操作,但您可以使用ProgressBar或SeekBar执行此操作:

  1. Create your ProgressBar, either horizonal or vertical.
  2. 创建ProgressBar,无论是水平还是垂直。

  3. Create a Runnable that changes the ProgressBar value: increment it until it hits the max and then sets it to zero and start over. You can pick the amount that it increments each time it runs based on the desired resolution.
  4. 创建一个更改ProgressBar值的Runnable:递增它直到达到最大值,然后将其设置为零并重新开始。您可以根据所需的分辨率选择每次运行时增加的量。

  5. Use postDelayed to schedule the Runnable on the ui thread, and every time the Runnable updates the values it will reschedule itself based on the interval you choose, which should control the speed.
  6. 使用postDelayed在ui线程上调度Runnable,每次Runnable更新值时,它将根据您选择的时间间隔重新安排自己,这应该控制速度。

  7. When someone taps the ProgressBar set a flag that stops the Runnable from updating the value.
  8. 当有人点击ProgressBar时,设置一个标志,阻止Runnable更新值。

You can then use the progress bar value as the final number.

然后,您可以使用进度条值作为最终数字。

See http://developer.android.com/reference/android/widget/ProgressBar.html for the ProgressBar details and http://developer.android.com/reference/android/view/View.html#postDelayed%28java.lang.Runnable,%20long%29 for the use of postDelayed.

有关ProgressBar的详细信息,请参阅http://developer.android.com/reference/android/widget/ProgressBar.html,http://developer.android.com/reference/android/view/View.html#postDelayed%28java.lang .Runnable,%20long%29使用postDelayed。

#1


0  

There is no pre-defined component to do this, but you can do this using a ProgressBar or SeekBar:

没有预定义的组件可以执行此操作,但您可以使用ProgressBar或SeekBar执行此操作:

  1. Create your ProgressBar, either horizonal or vertical.
  2. 创建ProgressBar,无论是水平还是垂直。

  3. Create a Runnable that changes the ProgressBar value: increment it until it hits the max and then sets it to zero and start over. You can pick the amount that it increments each time it runs based on the desired resolution.
  4. 创建一个更改ProgressBar值的Runnable:递增它直到达到最大值,然后将其设置为零并重新开始。您可以根据所需的分辨率选择每次运行时增加的量。

  5. Use postDelayed to schedule the Runnable on the ui thread, and every time the Runnable updates the values it will reschedule itself based on the interval you choose, which should control the speed.
  6. 使用postDelayed在ui线程上调度Runnable,每次Runnable更新值时,它将根据您选择的时间间隔重新安排自己,这应该控制速度。

  7. When someone taps the ProgressBar set a flag that stops the Runnable from updating the value.
  8. 当有人点击ProgressBar时,设置一个标志,阻止Runnable更新值。

You can then use the progress bar value as the final number.

然后,您可以使用进度条值作为最终数字。

See http://developer.android.com/reference/android/widget/ProgressBar.html for the ProgressBar details and http://developer.android.com/reference/android/view/View.html#postDelayed%28java.lang.Runnable,%20long%29 for the use of postDelayed.

有关ProgressBar的详细信息,请参阅http://developer.android.com/reference/android/widget/ProgressBar.html,http://developer.android.com/reference/android/view/View.html#postDelayed%28java.lang .Runnable,%20long%29使用postDelayed。