Android SeekBar水平翻转

编程入门 行业动态 更新时间:2024-10-24 16:27:07
本文介绍了Android SeekBar水平翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用Android SeekBar,通常可以将拇指向左或向右拖动,黄色进度色在拇指的左侧.我想要完全相反的方法,本质上是将黄色进度色翻转到拇指的右侧,并在y轴上翻转整个SeekBar.

With the Android SeekBar, you can normally drag the thumb to the left or to the right and the yellow progress color is to the left of the thumb. I want the exact opposite, essentially flipping the yellow progress color to the right of the thumb and flipping the entire SeekBar on the y-axis.

有人能指出我正确的方向吗?谢谢!

Can anyone point me in the right direction? Thanks!

推荐答案

在弄懂一些代码之后,这就是我所得到的,并且看起来工作得很好.希望它将对将来的其他人有所帮助.

After fiddling around with some code this is what I got and it seems to work pretty well. Hopefully it will help someone else in the future.

public class ReversedSeekBar extends SeekBar { public ReversedSeekBar(Context context) { super(context); } public ReversedSeekBar(Context context, AttributeSet attrs) { super(context, attrs); } public ReversedSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { float px = this.getWidth() / 2.0f; float py = this.getHeight() / 2.0f; canvas.scale(-1, 1, px, py); super.onDraw(canvas); } @Override public boolean onTouchEvent(MotionEvent event) { event.setLocation(this.getWidth() - event.getX(), event.getY()); return super.onTouchEvent(event); } }

这是在以下两个问题的帮助下抛出的:

This was thrown together with the help of these two questions:

  • 如何显示上方Android中具有textview的文本?
  • 如何在Android中获得可用的垂直SeekBar?
  • How can you display upside down text with a textview in Android?
  • How can I get a working vertical SeekBar in Android?
  • 更多推荐

    Android SeekBar水平翻转

    本文发布于:2023-10-08 02:45:05,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1471282.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:水平   Android   SeekBar

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!