How to decrease padding in NumberPicker

不想你离开。 提交于 2019-12-10 12:28:48

问题


How to decrease padding in NumberPicker

I want something like it:


回答1:


It's surprisingly easy to archive:


(scaleX and scaleY equals 2.5)


(without scaleX and scaleY)

    String[] values = {"Public", "Shared", "Private",....};

    NumberPicker np=
            (NumberPicker) findViewById(R.id.numberPicker);
    np.setMaxValue(values.length-1);
    np.setMinValue(0);
    np.setDisplayedValues(values);

And simply set small layout_height and scaleX, scaleX:

<NumberPicker
    android:id="@+id/numberPicker"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:scaleX="2.5"
    android:scaleY="2.5"/>

I do agree, that standard NumberPicker is hardly customizable, though.

I hope, it helps




回答2:


Unfortunately, number picker is not style-able.

I advise on using a library such as the one by SimonTV




回答3:


As Grebulon pointed its very simple to customize the picker if you are using the libray by .

These are the code and the results-

<net.simonvt.numberpicker.NumberPicker
        android:id="@+id/numberPicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:internalMaxHeight="100dp"
        app:selectionDividersDistance="30dp"/>

I was forked it once to increase the number of selector wheels. Here is the output of above code.




回答4:


This is probably a bit late but you can set the explicit height on the NumberPicker it then follows the given height and adjusts the space between the items.




回答5:


Try to customize your NumberPicker Theme like below:

    <style name="Widget.Holo.NumberPicker" parent="Widget.NumberPicker">
  <!-- Customize your theme here -->
  <item name="android:selectionDivider">@android:drawable/numberpicker_selection_divider</item>
  <item name="android:selectionDividerHeight">2dp</item>
  <item name="android:selectionDividersDistance">25dp</item>
  <item name="android:internalMinWidth">50dp</item>
  <item name="android:internalMaxHeight">100dp</item>

</style>

Hope it's help your.



来源:https://stackoverflow.com/questions/34600130/how-to-decrease-padding-in-numberpicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!