0

我必须让 NumberPicker 让用户在 0 - 4 之间进行选择,但不是每次都增加一...
我需要将它增加 0.05,例如 (0.05 - 0.1 - 0.15 - .... - 3.95 - 4)
以及哪些属性使 numberpicker 在设计中看起来不错 在此
先感谢

main_xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:orientation="vertical">
<NumberPicker
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/pick">
        </NumberPicker>
</LinearLayout>

MainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.NumberPicker;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grades_scale);
        NumberPicker numberPicker=(NumberPicker)findViewById(R.id.pick);
        numberPicker.setMinValue(0);
        numberPicker.setMaxValue(4);
        numberPicker.setWrapSelectorWheel(false);

    }
}
4

1 回答 1

1

您需要将 NumberPicker 格式化为值之间的“0.05”计数差异。

 NumberPicker.Formatter formatter = new NumberPicker.Formatter() {
                @Override
                public String format(int value) {
                    int diff = value * 0.05;
                    return "" + diff;
                }
            };
            numberPicker.setFormatter(formatter);

然后设置最大值和最小值。

numberPicker.setMinValue(0);
numberPicker.setMaxValue(4);

来自https://stackoverflow.com/a/30469826/4565874的回答

于 2016-09-23T05:56:14.543 回答