【问题标题】:how to make scrollable button in android如何在android中制作可滚动按钮
【发布时间】:2011-05-16 19:09:15
【问题描述】:

您好,我正在尝试为我的应用程序制作均衡器,但我不知道如何制作按钮。我真的不知道如何解释自己,所以这里有一张比我的话更能说明问题的图片:

我需要动画吗?你们能指出我正确的方向吗?

提前致谢。

【问题讨论】:

  • 在我看来,您需要创建自定义视图扩展 imagebutton 或 imageview 的按钮并处理触摸事件。这是新手的第一个想法。
  • @Madcoderz :我想在我的应用程序中创建一个音乐均衡器。你能帮我吗?

标签: android


【解决方案1】:

有一个很好的教程here 用于创建里程表小部件。这根本不是您想要的外观,但许多(大多数)相同的问题都适用,包括自定义渲染、处理触摸事件以及将一系列子小部件连接到更大的控件中。这是我看到你的图片时首先想到的。

【讨论】:

    【解决方案2】:

    这是简单的垂直 seekBar....

    public class SimpleVerticalSeekBar extends SeekBar {
    
        public SimpleVerticalSeekBar(Context context) {
            super(context);
        }
    
        public SimpleVerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public SimpleVerticalSeekBar(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
            super.onSizeChanged(h, w, oldh, oldw);
        }
    
        @Override
        protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(heightMeasureSpec, widthMeasureSpec);
            setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
        }
    
        protected void onDraw(Canvas c) {
            c.rotate(-90);
            c.translate(-getHeight(), 0);
    
            super.onDraw(c);
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (!isEnabled()) {
                return false;
            }
    
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_MOVE:
                case MotionEvent.ACTION_UP:
                    setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
                    onSizeChanged(getWidth(), getHeight(), 0, 0);
                    break;
    
                case MotionEvent.ACTION_CANCEL:
                    break;
            }
            return true;
        }
    }
    

    【讨论】:

      【解决方案3】:

      我想你的意思是SeekBar。是Android的JSlider。

      【讨论】:

      • 正是我想要的。非常感谢
      • @Ted 我发现this older 主题有同样的问题。
      • 是的,该线程上的建议也需要自定义小部件。我认为这比尝试继承 SeekBar 并强制它垂直操作要容易得多。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多