本文介绍了在Android上使用负值搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用我的code一个搜索栏与两个按钮来增加和减少values.The分钟和搜索栏的最大范围应为-30〜480
I am using a seek bar in my code with with two buttons to increment and decrement the values.The min and max range of seek bar should be from -30 to 480.
任何一个可以请建议如何设定的范围内寻求-30至480栏
Can any one please suggest how to set the range in seek bar from -30 to 480.
推荐答案
下面是一个I类用于此:
Here's a class I use for this:
import android.content.Context;
import android.support.v7.appcompat.R;
import android.util.AttributeSet;
import android.widget.SeekBar;
/**
* Created by HeWhoWas on 5/10/13.
*/
public class NegativeSeekBar extends SeekBar {
protected int minimumValue = 0;
protected int maximumValue = 0;
protected OnSeekBarChangeListener listener;
public NegativeSeekBar(Context context){
super(context);
setUpInternalListener();
}
public NegativeSeekBar(Context context, AttributeSet attrs){
super(context, attrs);
setUpInternalListener();
}
public NegativeSeekBar(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
setUpInternalListener();
}
public void setMin(int min){
this.minimumValue = min;
super.setMax(maximumValue - minimumValue);
}
public void setMax(int max){
this.maximumValue = max;
super.setMax(maximumValue - minimumValue);
}
@Override
public void setOnSeekBarChangeListener(OnSeekBarChangeListener listener){
this.listener = listener;
}
private void setUpInternalListener(){
super.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
if(listener != null){
listener.onProgressChanged(seekBar, minimumValue + i, b);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
if(listener != null)
listener.onStartTrackingTouch(seekBar);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if(listener != null)
listener.onStopTrackingTouch(seekBar);
}
});
}
}
这篇关于在Android上使用负值搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!