この NumberPicker のレイアウトでは、 + ボタンが上にあるために、+ ボタンを押している間、設定している値が指で見えなくなってしまいます。そこで、この NumberPicker を元にして + ボタンと - ボタンが設定値の左右にある Picker を作ってみました。
ItemPicker at yanzm/yanzm-s-Custom-View-Project - GitHub
ついでに、ボタンと入力部分の画像リソースと、選択範囲および選択アイテムを attribute として指定できるようにしました。
こんな感じで、XML から値の設定などが全部できます。
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:custom="http://schemas.android.com/apk/res/yanzm.products.customview.itempicker"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <DatePicker
- android:id="@+id/datePicker1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- <TimePicker
- android:id="@+id/timePicker1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- <yanzm.products.customview.itempicker.ItemPicker
- android:layout_width="180dip"
- android:layout_height="wrap_content"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:text="+"
- custom:start="0"
- custom:end="10"
- custom:current="2"
- />
- <yanzm.products.customview.itempicker.ItemPicker
- android:layout_width="240dip"
- android:layout_height="wrap_content"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:text="+"
- custom:start="1"
- custom:end="9"
- custom:current="2"
- custom:speed="100"
- custom:displayedValue="@array/color_names"
- />
- <yanzm.products.customview.itempicker.ItemPicker
- android:layout_width="240dip"
- android:layout_height="wrap_content"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:text="+"
- custom:start="1"
- custom:end="9"
- custom:current="4"
- custom:incrementBackground="@drawable/picker_bg"
- custom:decrementBackground="@drawable/picker_bg"
- custom:editTextBackground="@drawable/input_bg"
- custom:displayedValue="@array/color_names"
- />
- </LinearLayout>
attribute として用意したのは
- incrementSrc : 増加ボタン (ImageButton) の 画像リソース
- decrementSrc : 減少ボタン (ImageButton) の画像リソース
- incrementBackground : 増加ボタン (ImageButton) の 背景画像リソース
- decrementBackground : 減少ボタン (ImageButton) の背景画像リソース
- editTextBackground : 設定値 (EditText) の背景画像リソース
- start : 最少値 (int)
- end : 最大値 (int)
- current : 現在の値 (int)
- speed : ボタン長押し時の自動増加/減少の切り替え速度
- displayedValue : 数字ではなく文字を設定値にする場合の文字列配列。最小値が index 0 にあたる
0 件のコメント:
コメントを投稿