gpt4 book ai didi

android - VerticalSeekBar 和事件

转载 作者:行者123 更新时间:2023-11-29 16:11:05 25 4
gpt4 key购买 nike

这是我的 VerticalSeeker 类:

public class VerticalSeekBar extends SeekBar implements SeekBar.OnSeekBarChangeListener{

public VerticalSeekBar(Context context) {
super(context);
this.setOnSeekBarChangeListener(this);
}

public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}

public 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((int) (getMax() * event.getY() / getHeight()) - 0);
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;

case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}

@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}

@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
Toast.makeText(this.getContext(), "Start", Toast.LENGTH_SHORT).show();
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(this.getContext(), "Stop", Toast.LENGTH_SHORT).show();
}

有人能解释一下,为什么只有“onProgressChanged”事件在触发吗?如何让“onStartTrackingTouch”和“onStopTrackingTouch”起作用?

最佳答案

至少将您的 Motion 事件 switch case 代码更改为

case MotionEvent.ACTION_UP:
setProgress(getMax()- (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);
onChangeListener.onStopTrackingTouch(this);

http://hackskrieg.wordpress.com/2012/04/20/working-vertical-seekbar-for-android/ 找到了完整的实现

关于android - VerticalSeekBar 和事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13229931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com