2014-10-22 4 views
5

सभी में फ़ॉन्ट आकार को कम करने, मैं एक शहर पिकर है, जो तीन numberPicker अंदर का उपयोग करता है, इस तरह अनुकूलित कर रहा हूँ: enter image description hereकैसे NumberPicker

यह एक चीनी प्रांत-शहर-क्षेत्र चयनकर्ता।

कोड:

String[] areas = get_from_somewhere(); 
areaPicker.setDisplayedValues(areas); 

मैं फ़ॉन्ट आकार, किसी भी सलाह को कम करना चाहते हैं?

समाधान: Refer to this

+0

आप कस्टम 'व्हील व्यू' का उपयोग कर रहे हैं जो 'व्यू' बढ़ाता है, है ना? – Rustam

+0

@ रुस्तम हाँ, मैं एंड्रॉइड शैली में एक व्हीलव्यू चाहता हूं। गितब https://github.com/ywenblocker/Provinces- पिकर -व्हील पर एक नमूना की स्थापना की, लेकिन यह होलो थीम फिट नहीं है। मुझे और जानकारी दें, कृपया – Ninja

+0

बेहतर तरीके से इस https://github.com/mstorsjo/vlc-android/tree/master/java-libs/WheelView/src/kankan/wheel/widget – Rustam

उत्तर

7

आप इस के लिए अपने कस्टम वर्ग CustomNumberPicker में डिफ़ॉल्ट NumberPicker विस्तार कर सकते हैं:

public class CustomNumberPicker extends NumberPicker { 

    public NumberPicker(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    public void addView(View child) { 
     super.addView(child); 
     if(child instanceof EditText) { 
      ((EditText) child).setTextSize(25); 
     } 
    } 
} 

अब CustomNumberPicker साथ एक्सएमएल में अपने वर्तमान NumberPicker बदल देते हैं:

<com.pkg.name.CustomNumberPicker 
    android:id="@+id/number_picker" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
+0

आपके उत्तर का धन्यवाद, मैंने ((EditText) दृश्य पर ब्रेकपॉइंट सेट किया है) .setTextSize (25); लेकिन कुछ भी नहीं हुआ – Ninja

+0

क्या आपने अपने एक्सएमएल या गतिविधि में नंबरपिकर की बजाय कस्टम नम्बरपिकर का उपयोग किया था? –

+0

हां, मैं अपने कंस्ट्रक्टर में "प्रांतपिकर = नया स्मॉलसाइज नम्बरपिकर (संदर्भ, शून्य);" का उपयोग करता हूं, ब्रेक पॉइंट कभी भी आमंत्रित नहीं होता है। मैं कीवर्ड 'addView (' को NumberPicker.java के स्रोत में, और कुछ भी नहीं मिला। – Ninja

8

तकनीकी रूप से फ़ॉन्ट आकार को नहीं बदलते हुए, टेक्स्ट का आकार पूरे नंबरपिकर व्यू के पैमाने को बदलकर बदला जा सकता है।

<NumberPicker 
    android:id="@+id/number_picker" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scaleX=".7" 
    android:scaleY=".7"/> 
1

जॉन स्टारबर्ड उत्तर के आधार पर।

आप शैली जोड़ते हैं।

<style name="NumberPickerText"> 
    <item name="android:textSize">11dp</item> 
</style> 

एक्सएमएल में अपने नंबर पिकर में शैली जोड़ें।

android:theme="@style/NumberPickerText" 
संबंधित मुद्दे