2011-11-02 12 views
6

का सारांश क्षेत्र मैं कुछ इस तरह देखा है:PreferenceCategory टैग

<PreferenceCategory xmlns:android="http://schemas.android.com/apk/res/android" 
    android:key="vegi_category" android:title="Vegetables" 

    android:summary="Preferences related to vegetable"> <!-- Why is this here? --> 

    <CheckBoxPreference android:key="tomato_selection_pref" 
     android:title="Tomato " android:summary="It's actually a fruit" /> 
    <CheckBoxPreference android:key="potato_selection_pref" 
     android:title="Potato" android:summary="My favorite vegetable" /> 
</PreferenceCategory> 

लेकिन मैं क्यों वरी श्रेणी के लिए एक सारांश क्षेत्र है यह नहीं मिलता है:

(android:summary="Preferences related to vegetable")?

जब मैं प्रीफ स्क्रीन का उपयोग करता हूं तो सारांश दृश्य में प्रस्तुत किया जाता है, लेकिन यह pref श्रेणी के साथ कोई मामला नहीं है। क्या प्रीफ श्रेणी में सारांश का अस्तित्व सिर्फ इसका एक सम्मेलन देखा जा सकता है?

प्रीफ़ श्रेणी तत्व में सारांश का वास्तविक उपयोग क्या है?

उत्तर

9

मानक वरीयता श्रेणी विजेट केवल शीर्षक दिखाता है; android:summary विशेषता को अनदेखा किया जाता है।

ऐसा इसलिए है क्योंकि डिफ़ॉल्ट लेआउट (preference_category.xml) शीर्षक क्षेत्र के लिए केवल एक ही TextView शामिल है:

<!-- Layout used for PreferenceCategory in a PreferenceActivity. --> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    style="?android:attr/listSeparatorTextViewStyle" 
    android:id="@+android:id/title" 
/> 

आप के रूप में अच्छी सारांश दिखाने के लिए चाहते हैं, आप android:layout विशेषता का उपयोग अपने स्वयं के लेआउट निर्दिष्ट कर सकते हैं। उदाहरण के लिए:

<PreferenceCategory android:title="Category" android:summary="This is the summary" 
        android:layout="@layout/preference_category_summary"> 

कहाँ लेआउट/preference_category_summary.xml की तरह कुछ है:

<!-- Layout used for PreferenceCategory + SUMMARY in a PreferenceActivity. --> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:orientation="vertical"> 
    <TextView android:id="@+android:id/title" 
       style="?android:attr/listSeparatorTextViewStyle"/> 
    <TextView android:id="@+android:id/summary" 
       android:paddingLeft="5dip" android:paddingRight="dip" 
       android:layout_width="match_parent" android:layout_height="wrap_content"/> 
</LinearLayout> 

इससे पहले कि आप आगे जाना है और ऐसा करते हैं, हालांकि, आप पर विचार करना चाहिए कि क्या यह कम या उपयोगकर्ता के लिए और अधिक भ्रामक है। जब तक आप सारांश पाठ सावधानी से तैयार नहीं करते हैं, तो यह या तो स्क्रीन से बाहर निकल जाएगा या श्रेणी में पहली वरीयता से संलग्न होगा।

7

आप वरीयता और एंड्रॉइड का उपयोग कर सकते हैं: सारांश।

<PreferenceCategory xmlns:android="http://schemas.android.com/apk/res/android" 
    android:key="vegi_category" android:title="Vegetables"> 

    <Preference android:summary="Preferences related to vegetable" /> 

    <CheckBoxPreference android:key="tomato_selection_pref" 
     android:title="Tomato " android:summary="It's actually a fruit" /> 
    <CheckBoxPreference android:key="potato_selection_pref" 
     android:title="Potato" android:summary="My favorite vegetable" /> 
</PreferenceCategory> 
+0

इस काम करता है। लेकिन बहुत अच्छा प्रदर्शन नहीं –

+0

मुझे लगता है कि यह बहुत अच्छी तरह से काम करता है (लेआउट बदलने की तुलना में, क्योंकि इसे एंड्रॉइड वर्जन को देखने और महसूस करने की आवश्यकता है)। इसके अतिरिक्त यदि आप 'android: selectable = false' जोड़ते हैं तो आप समान दिखने और महसूस कर सकते हैं। –

0

@ehartwell बिल्कुल सही है
diff संस्करणों के लिए मेरी लेआउट हैं:

के लिए पूर्व लॉलीपॉप

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <TextView android:id="@android:id/title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="6dp" 
    android:textSize="14sp" 
    android:textStyle="bold" 
    android:textAllCaps="true" 
    android:paddingLeft="8dp" 
    android:paddingRight="8dp"/> 

    <TextView android:id="@android:id/summary" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="-5dp" 
    android:textSize="12sp" 
    style="?android:attr/listSeparatorTextViewStyle"/> 

</LinearLayout> 

के लिए बाद लॉलीपॉप

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="@dimen/preference_category_margin" 
    android:paddingRight="@dimen/preference_category_margin" 
    android:orientation="vertical"> 

    <TextView android:id="@android:id/title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="6dp" 
    android:textStyle="bold" 
    android:textSize="13sp" 
    android:textAllCaps="false" 
    android:textColor="@color/colorAccent"/> 

    <TextView android:id="@android:id/summary" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textSize="12sp" 
    android:textColor="@color/colorAccent" 
    android:textAllCaps="false"/> 

</LinearLayout> 

@ Dimen/preference_category_margin विशेष स्क्रीन आकार के लिए अन्तर है
16dp या 24dp
और वे बहुत अच्छी तरह से कर रहे हैं :)

संबंधित मुद्दे