這裏是我的電話號碼選擇器,我使用的日期和時間:
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.NumberPicker;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)//For backward-compability
public class NumberPickerMinMax extends NumberPicker
{
public NumberPickerMinMax(Context context)
{
super(context);
}
public NumberPickerMinMax(Context context, AttributeSet attrs)
{
super(context, attrs);
processAttributeSet(attrs);
}
public NumberPickerMinMax(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
processAttributeSet(attrs);
}
private void processAttributeSet(AttributeSet attrs)
{
//This method reads the parameters given in the xml file and sets the properties according to it
this.setMinValue(attrs.getAttributeIntValue(null, "min", 0));
this.setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
}
}
現在,你需要添加4 NumberPickerMinMax
的時間每個數字:HH:MM,這裏是我的佈局:
<?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" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<com.evapp.customViews.NumberPickerMinMax
android:id="@+id/TimePickerView_hour2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
min="0"
max="9"
android:layout_toLeftOf="@+id/textView1" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=" - "
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.evapp.customViews.NumberPickerMinMax
android:id="@+id/TimePickerView_hour1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="2dp"
min="0"
max="2"
android:layout_toLeftOf="@+id/TimePickerView_hour2" />
<com.evapp.customViews.NumberPickerMinMax
android:id="@+id/TimePickerView_minutes1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
min="0"
max="5"
android:layout_toRightOf="@+id/textView1" />
<com.evapp.customViews.NumberPickerMinMax
android:id="@+id/TimePickerView_minutes2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
min="0"
max="9"
android:layout_toRightOf="@+id/TimePickerView_minutes1" />
</RelativeLayout>
</RelativeLayout>
^h這是你需要的
你能解釋你想達到什麼嗎?我不明白你的問題。 –