NumberPickerView
#####Another NumberPicker with more flexible attributes on Android platform
[English] 6
##?? ?Android????????? NumberPicker
?????????? NumberPicker
???????????????????????????????????????????????????????????
###????
NumberPickerView??????????????/?????View??????????
?????????????????divider???????????????????????
https://github.com/Carbs0126/GregorianLunarCalendar
###??
NumberPickerView
????android?? NumberPicker
????????????? View
? ?????????????????????????????????? NumberPicker
????????????????????????
####??????-NumberPicker
- ????????3??????
- ?fling?????????????
- ????????????????
- ???????????????????
- ????wrap???(
setWrapSelectorWheel()
??)???“??????????”???? - ???????????
- ????????????????item?
####???????-NumberPickerView
- ???????????????
- fling????????????????????????????????2?
mNumberPickerView.setFriction(2 * ViewConfiguration.get(mContext).getScrollFriction());
- ????????????????????????????????????????
- ?????????????????????????????
- ?????????wrap??????????
- ??????????????????????????
- ????????????????????
- ??
wrap_content
???item?padding - ?????????UI??
- ?????????
onValueChanged()
- ???????????????????????
- ???????
onValueChanged
??????????? - ??NumberPicker?????????
???????
setOnValueChangedListener()
setOnScrollListener()
setDisplayedValues()/getDisplayedValues()
setWrapSelectorWheel()/getWrapSelectorWheel()
setMinValue()/getMinValue()
setMaxValue()/getMaxValue()
setValue()/getValue()
?????????
OnValueChangeListener
OnScrollListener
???????
OnValueChangeListenerInScrolling//???????value change
###????
1.?????
compile 'cn.carbswang.android:NumberPickerView:1.1.1'
??
<dependency>
<groupId>cn.carbswang.android</groupId>
<artifactId>NumberPickerView</artifactId>
<version>1.1.1</version>
<type>pom</type>
</dependency>
2.??????NumberPickerView
<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/picker"
android:layout_width="wrap_content"
android:layout_height="240dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#11333333"
android:contentDescription="test_number_picker_view"
app:npv_ItemPaddingHorizontal="5dp"
app:npv_ItemPaddingVertical="5dp"
app:npv_ShowCount="5"
app:npv_RespondChangeOnDetached="false"
app:npv_TextSizeNormal="16sp"
app:npv_TextSizeSelected="20sp"
app:npv_WrapSelectorWheel="true"/>
3.Java?????? 1)??????(String[] mDisplayedValues)??????????????????????NumberPicker????????
picker.setMinValue(minValue);
picker.setMaxValue(maxValue);
picker.setValue(value);
2)??????(String[] mDisplayedValues)?????????????????????NumberPicker??????????
int minValue = getMinValue();
int oldMaxValue = getMaxValue();
int oldSpan = oldMaxValue - minValue + 1;
int newMaxValue = display.length - 1;
int newSpan = newMaxValue - minValue + 1;
if (newSpan > oldSpan) {
setDisplayedValues(display);
setMaxValue(newMaxValue);
}
else {
setMaxValue(newMaxValue);
setDisplayedValues(display);
}
??????NumberPickerView??????
refreshByNewDisplayedValues(String[] display)
???????????????????minValue?????????display????null????????0? 3)??????????value change???
picker.setOnValueChangeListenerInScrolling(...);
4.???NumberPickerView???????????
public void smoothScrollToValue(int fromValue, int toValue, boolean needRespond)
???? setValue(int)
??????????????????item????????????? NumberPickerView
????????? fromValue
?????????? toValue
?????? needRespond
?????????????? onValueChanged
????????? NumberPickerView
??????????? NumberPickerView
???????????????? onValueChanged
???????????????????? needRespond
?? false
???????????????
????????????????????????????? onCreate(Bundle savedInstanceState)
????????scroll?????????????? onCreate(Bundle savedInstanceState)
????????????
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//????
mNumberPickerView.post(new Runnable() {
@Override
public void run() {
//??smoothScrollToValue()??????
}
}
);
}
5.??????????
<declare-styleable name="NumberPickerView">
<attr name="npv_ShowCount" format="reference|integer" />//??????????3?
<attr name="npv_ShowDivider" format="reference|boolean" />//??????divider?????
<attr name="npv_DividerColor" format="reference|color" />//??divider???
<attr name="npv_DividerMarginLeft" format="reference|dimension" />//divider??????
<attr name="npv_DividerMarginRight" format="reference|dimension" />//divider??????
<attr name="npv_DividerHeight" format="reference|dimension" />//divider???
<attr name="npv_TextColorNormal" format="reference|color" />//????????
<attr name="npv_TextColorSelected" format="reference|color" />//???????
<attr name="npv_TextColorHint" format="reference|color" />//????????????
<attr name="npv_TextSizeNormal" format="reference|dimension" />//????????
<attr name="npv_TextSizeSelected" format="reference|dimension" />//???????
<attr name="npv_TextSizeHint" format="reference|dimension" />//???????
<attr name="npv_TextArray" format="reference" />//?????stringarray??
<attr name="npv_MinValue" format="reference|integer" />//?????setMinValue()
<attr name="npv_MaxValue" format="reference|integer" />//?????setMaxValue()
<attr name="npv_WrapSelectorWheel" format="reference|boolean" />//????wrap??setWrapSelectorWheel
<attr name="npv_HintText" format="reference|string" />//??????
<attr name="npv_EmptyItemHint" format="reference|string" />//????????????????????WrapSelectorWheel==false????
<attr name="npv_MarginStartOfHint" format="reference|dimension" />//????????????"??"????array??item???
<attr name="npv_MarginEndOfHint" format="reference|dimension" />//???????????
<attr name="npv_ItemPaddingHorizontal" format="reference|dimension" />//item???padding???wrap_content??
<attr name="npv_ItemPaddingVertical" format="reference|dimension" />//item???padding???wrap_content??
<attr name="npv_RespondChangeOnDetached" format="reference|boolean" />//?detach???NumberPickerView???????
//????onValueChange???????Dialog/PopupWindow??????
//????????????????????Dialog/PopupWindow????????????????????false
<attr name="npv_RespondChangeInMainThread" format="reference|boolean" />//??`onValueChanged`?????????????
//???`true`???????????????`false`?????????
//???????wrap_content????????array????????"??"????????????????????
<!--just used to measure maxWidth for wrap_content without hint,
the string array will never be displayed.
you can set this attr if you want to keep the wraped numberpickerview
width unchanged when alter the content list-->
<attr name="npv_AlternativeTextArrayWithMeasureHint" format="reference" />//????????????????????????????String?????
<attr name="npv_AlternativeTextArrayWithoutMeasureHint" format="reference" />//?????????????????????????????String???+????+????marginstart +????marginend ??
<!--the max length of hint content-->
<attr name="npv_AlternativeHint" format="reference|string" />//?????????
</declare-styleable>
###????
####1.1.1 1.??????typeface???
2.?????????valuechange???
picker.setOnValueChangeListenerInScrolling(...);
####1.1.0 1.?????????????
2.???????
3.???????????
####1.0.9 1.????`app:npv_RespondChangeInMainThread="true"`???`onValueChanged`????????????????`true`???????????????`false`?????????
2.??`TimePickerActivity`????????`app:npv_RespondChangeInMainThread="true"`????
3.??bug: ?????????????????????????????????????bug?
####1.0.8 1.??`stopScrolling`????`abortAnimation()`??????????????
2.??`npv_RespondChangeOnDetached`?????false
####1.0.7 1.???`onDetachToWindow()`???????????????????`Dialog/PopupWindow`?????`Dialog/PopupWindow`?????`NumberPickerView`??????????????+????`OnValueChange`??+?????????????`npv_RespondChangeOnDetached`????????onValueChange?????????NumberPickerView???????????????`Dialog/PopupWindow`???????NumberPickerView?????????`npv_RespondChangeOnDetached`????false?????`GregorianLunarCalendar`????dialog??????????????????????????????????
####1.0.6 1.?`onDetachToWindow()`???????????????????Dialog/PopupWindow
####1.0.5 1.?`onAttachToWindow()`???????`mHandlerThread`??????`quit`?????????????dialog/popupWindow??????????
####1.0.4 1.???????????????
####1.0.3 1.??????`ScrollView`????bug???anjiao??Elektroktay?issue
###????
####1.???????? Scroller
+ VelocityTracker
+ onDraw(Canvas canvas)
####2.??????? Handler
??????
####3.???UI?? ??UI????????????????????item?????????????????item???????????
###?NumberPicker??NumberPickerView
?????????NumberPicker???????NumberPicker???????????NumberPicker????NumberPicker????????NumberPickerView???
###? UI?????meizu???????????google?android????meizu????
??????????Star????
????????? email: [email protected]
License
Copyright 2016 Carbs.Wang (NumberPickerView) Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.