Android的搜索栏最小和连续浮点值的属性 [英] Android SeekBar Minimum and Continuous Float Value Attributes

查看:109
本文介绍了Android的搜索栏最小和连续浮点值的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方式来实现我的搜索栏的最小值,也有递增的十进制数的选项。例如,目前我的搜索栏的最小值设置为0,但我需要它的值0.2开始。另外,我想具备的功能,能够让用户在.1 precision从0.2号至10.0,使他们可以选择数字5.6或7.1。

I'm looking for a way to implement a minimum value in my SeekBar and also have the option to increment decimal numbers. For example, currently my SeekBar's minimum is set to 0, but I need it to start at the value 0.2. Also, I would like to have the functionality to be able to have the user select a number from 0.2 to 10.0 at a .1 precision so they can choose the numbers 5.6 or 7.1.

下面是我的搜索栏的样式属性:

Here are the style attributes for my SeekBar:

 <style name="SeekBar">
            <item name="android:paddingLeft">30dp</item>
            <item name="android:paddingRight">30dp</item>
            <item name="android:layout_width">fill_parent</item>
            <item name="android:layout_height">wrap_content</item>
            <item name="android:layout_marginTop">0dp</item>
            <item name="android:layout_marginBottom">0dp</item>
            <item name="android:max">10</item>
            <item name="android:progress">1</item>

    </style>


推荐答案

这可用于进度的值被限制为值零和,我们选择一些最大值之间。不过,我们可以扩展与算术运算这些值。允许例如在XML文件设定的最大值为200。然后改变Java code以下列方式。

The values that can be used for the progress are limited to values between zero and some max value that we choose. We can however scale these values with arithmetic operations. Lets for example set the max value to 200 in the XML-file. Then change the java code in the following way.

@Override 
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

    sliderValueTW.setText(Float.toString((float)(progress-100)/10)); 

}

其结果是出现滑块用户从-10.0去10.0与0.1个单位的增量。

The result is that the slider appears to the user to be going from -10.0 to 10.0 with increments of 0.1 units.

这篇关于Android的搜索栏最小和连续浮点值的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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