Search code examples
androidnumberpicker

NumberPicker rendered incorrectly in a Dialog


I have a NumberPicker inside an AlertDialog instantiated like this: final NumberPicker np = new NumberPicker(PiattoActivity.this);.

The problem is, instead of being rendered like this (on the left):

from android docs

it's rendered like this:

Why the dividers take up all the space given? How can I fix it?


Solution

  • You are using for the picker

    android:layout_width="match_parent"
    

    You should use

        android:layout_width="wrap_content"
        android:layout_gravity="center"