我想创建一个带有显示值数组的 NumberPicker。当显示 NumberPicker 时,这些值不应更改,但最小值和最大值会根据用户操作动态更改。
这是代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<NumberPicker
android:id="@+id/picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
在主要活动中
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String[] values = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
NumberPicker picker = (NumberPicker) findViewById(R.id.picker);
picker.setDisplayedValues(values);
picker.setMaxValue(7);
picker.setMinValue(3);
picker.setWrapSelectorWheel(false);
}
}
当我设置最大值而不设置最小值时,我会以“0”和“7”(包括)之间的显示值结束。如果我将 minValue 设置为 0 我有相同的行为。但是,如果我将 minValue 设置为 3,我会以“0”和“4”之间的显示值结束。当它应该在“3”和“7”之间时。
我不明白为什么。我做错了什么还是组件有问题?