2011-11-02 27 views
6

özet alanı:Böyle bir şey gördük PreferenceCategory etiketi

<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> 

Ama nedenini terc kategori için bir özet alan vardır o alamadım:

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

Pref ekranı kullandığımda, özet görünümde sunulur, ancak bu, pref kategorisinde bir durum değildir. Pref kategorisinde özetin varlığı sadece bir sözleşmesi bir şekilde görülebilir mi?

Pref kategorisi öğesinde özetin gerçek kullanımı nedir?

cevap

9

Standart PreferenceCategory küçük aracı yalnızca başlığı gösterir; android:summary özniteliği yoksayılır. siz de özetini göstermek için isterseniz, android:layout özelliğini kullanarak kendi düzenini belirtebilirsiniz

<!-- 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" 
/> 

: Varsayılan düzen (preference_category.xml) başlık alanı için yalnızca tek bir TextView içerdiğinden var

. Örneğin:

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

düzen/preference_category_summary.xml gibi bir şey Nerede:

<!-- 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> 

devam edip Bunu yapmadan önce, ancak, kullanıcıya daha az ya da daha çok kafa karıştırıcı karar vermelidir. Özet metnini dikkatlice biçimlendirmedikçe, ekrandan dışarı atlar veya kategorideki ilk tercihe eklenecek gibi görünür.

7

Tercihi ve android: özetini kullanabilirsiniz.

<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

bu işleri özel ekran boyutu için diff edilir. ama çok iyi bir performans değil –

+0

Bunun çok iyi çalıştığını görüyorum (düzeni değiştirmeye kıyasla, Android sürümüne benzemesi ve hissetmesi gerekiyor). Ayrıca eklediyseniz 'android: selectable = false' benzer bir görünüm ve his elde edebilirsiniz. –

0

@ehartwell fark sürümleri için
benim düzenleri vardır kesinlikle haklı:
için
için

<?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> 

sonrası lolipop öncesi lolipop

<?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 veya 24dp
ve oldukça iyi olan :)

İlgili konular