Android的搜索栏float值从0.0到2.0 [英] Android Seekbar float values from 0.0 to 2.0

查看:350
本文介绍了Android的搜索栏float值从0.0到2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能从0.0的值,以2.0与搜索栏?值应该在0.5以下步骤(0.0,0.5,1.0,1.5,2.0)
有人可以帮我吗?

how can I get the values ​​from 0.0 to 2.0 with a seekbar? values ​​should go in steps of 0.5 ( 0.0 , 0.5 , 1.0, 1.5, 2.0) can someone help me?

推荐答案

搜索栏扩展进度。

进度有一个方法

public void setMax(int max)

由于它只接受INT,你就必须做从int值某些转换来获取你所追求的浮动。

Since it only accepts int you'll have to do some conversion from an int value to get the float that you are after.

这样的事情应该做的伎俩:

Something like this should do the trick:

mSeekBar.setMax(4);
//max = 4 so the possible values are 0,1,2,3,4
seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener(){
    public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
    {
        // TODO Auto-generated method stub
        Toast.makeText(seekBar.getContext(), "Value: "+getConvertedValue(progress), Toast.LENGTH_SHORT).show();
    }
    public void onStartTrackingTouch(SeekBar seekBar)
    {
        // TODO Auto-generated method stub
    }
    public void onStopTrackingTouch(SeekBar seekBar)
    {
        // TODO Auto-generated method stub
    }
});

这部分将在你的onCreate(),你将不得不使用findViewById()或东西去mSeekBar参考。

This part will be in your onCreate() and you'll have to use findViewById() or something to get a reference to mSeekBar.

public float getConvertedValue(int intVal){
    float floatVal = 0.0;
    floatVal = .5f * intVal;
    return floatVal;
}

这部分是可以添加到您的活动另一种方法,将INT转换成你所需要的范围内浮动值。

This part is another method that you can add to your Activity that will convert from int to float values within the range you need.

这篇关于Android的搜索栏float值从0.0到2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆