Android实现垂直型的SeekBar


今天给大家推荐一个Android垂直型的SeekBar,可能对于你们在项目中有所帮助。这个已经有人具体实现。本人只是在这里稍做推荐。有关更多的好的控件本人在网上已建了一个网站专门做Android开源控件的收录以及示例代码的各种使用用法,目的是帮助更多的Android开发者,让更多的人爱上Android开发者。可以给出具体实现的思想及代码。

相关阅读:Android 垂直Seekbar【源码】

按以前写作方式,首先上效果图:

具体实现方式是继续SeekBar,重写onDraw方法只要旋转90度就可以实现。

给出以上两个其中的一个代码:

package android.widget;
 
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
 
public class VerticalSeekBar extendsSeekBar {
 
  public VerticalSeekBar(Context context) {
      super(context);
    }
 
  public VerticalSeekBar(Context context, AttributeSet attrs, intdefStyle) {
      super(context, attrs, defStyle);
    }
 
    public VerticalSeekBar(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, intheightMeasureSpec) {
      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:
                    int i=0;
                    i=getMax() - (int)(getMax() * event.getY() / getHeight());
                setProgress(i);
              Log.i("Progress",getProgress()+"");
                onSizeChanged(getWidth(),getHeight(), 0, 0);
                break;
 
          case MotionEvent.ACTION_CANCEL:
                break;
      }
      return true;
    }
 
}

  • 1
  • 2
  • 下一页

相关内容

    暂无相关文章