Create a number picker in horizontal mode, did android:orientation="horizontal" work? I have try but the number picker still same in vertical mode

Wg Sam picture Wg Sam · Dec 6, 2015 · Viewed 16.3k times · Source

I want to create a number picker in horizontal mode, but i set the android:orientation="horizontal", it still cannot work. How can i create the number picker in horizontal mode just like the pic below ?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.example.sam.weighttrack.KeyInWeightF">

    <LinearLayout
        android:id="@+id/payment2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >

        <NumberPicker
            android:id="@+id/numberPicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" />
    </LinearLayout>
</RelativeLayout>

Answer

user5642448 picture user5642448 · Dec 6, 2015

NumberPicker does not support horizontal orientation. So you have to write your own or use one of few existed libraries:

  1. HorizontalPicker
  2. android-spinnerwheel