2014-11-22 18 views
5

Uygulamamın özel düzeni ile özel bir tercih vardır ve uygulamanızı android 5 üzerinde denedikten sonra, özel tercihlerimin (yazı tipi boyutu, renk, dolgu) farklı görünmesini fark ettim. diğerleri. Bu yüzden, benim değişiklikleri ile birleştiren ve layout-v21 klasörüne yeni bir düzen koyarak, android 5 SDK'dan preference.xml alarak kolay bir düzeltme olacağını düşündüm. Bu sabit dolgu ve renk sorunları, ancak daha büyük olan başlık boyutunu değil.Özel tercih başlık yazı tipi boyutu, standart 5 standarttan daha büyüktür.

Benim özel tercihi yapıcı şuna benzer:

public SeekBarPreference(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    setLayoutResource(R.layout.preference_seekbar); 
} 

preference_seekbar.xml (sadece orijinal düzeni için seekbar eklendi):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:gravity="center_vertical" 
    android:paddingEnd="?android:attr/scrollbarSize" 
    android:background="?android:attr/selectableItemBackground" > 

    <ImageView 
     android:id="@+android:id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     /> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="15dip" 
     android:layout_marginEnd="6dip" 
     android:layout_marginTop="6dip" 
     android:layout_marginBottom="6dip" 
     android:layout_weight="1"> 

     <TextView android:id="@+android:id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:ellipsize="marquee" 
      android:fadingEdge="horizontal" /> 

     <TextView android:id="@+android:id/summary" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@android:id/title" 
      android:layout_alignStart="@android:id/title" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="?android:attr/textColorSecondary" 
      android:maxLines="4" /> 

     <SeekBar android:id="@+id/seekbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+android:id/title" 
      android:layout_toEndOf="@android:id/summary" 
      android:layout_toStartOf="@android:id/widget_frame"/> 

    </RelativeLayout> 

    <!-- Preference should place its actual preference widget here. --> 
    <LinearLayout android:id="@android:id/widget_frame" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:gravity="center_vertical" 
     android:orientation="vertical" /> 

</LinearLayout> 

O başlık widget'ı yukarıda fark edebilirsiniz bu orijinal özelliğe sahiptir : android:textAppearance="?android:attr/textAppearanceLarge", yazı tipi büyük olmalı, ancak sonra standart düzeni başlık yazı tipi boyutu aynı düzeni (sadece seekbar olmadan) kullanıyorsa daha küçük bir soru var mı?

cevap

1

Aynı sorunla karşılaşmış olsaydınız, solution here'u buldu.

TextView başlığı için textAppearanceListItem'u kullanmamama rağmen, bana daha uygun görünüyor.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:gravity="center_vertical" 
    android:paddingStart="?attr/listPreferredItemPaddingStart" 
    android:paddingEnd="?attr/listPreferredItemPaddingEnd"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:minWidth="@dimen/preference_icon_minWidth" 
     android:orientation="horizontal"> 
     <ImageView 
      android:id="@+android:id/icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:minWidth="48dp" 
      /> 
    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="16dip" 
     android:layout_marginEnd="8dip" 
     android:layout_marginTop="6dip" 
     android:layout_marginBottom="6dip" 
     android:layout_weight="1"> 

     <TextView android:id="@+android:id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:ellipsize="marquee" 
      android:fadingEdge="horizontal" /> 

     <TextView android:id="@+android:id/summary" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@android:id/title" 
      android:layout_alignStart="@android:id/title" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="?android:attr/textColorSecondary" 
      android:maxLines="4" /> 

     <!-- Preference should place its actual preference widget here. --> 
     <LinearLayout android:id="@+android:id/widget_frame" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_below="@android:id/summary" 
      android:layout_alignStart="@android:id/title" 
      android:minWidth="@dimen/preference_widget_width" 
      android:gravity="center" 
      android:orientation="vertical" /> 

     <SeekBar android:id="@+android:id/seekbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@android:id/summary" 
      android:layout_toEndOf="@android:id/widget_frame" 
      android:layout_alignParentEnd="true" /> 

    </RelativeLayout> 

</LinearLayout> 
+0

Bu benim için çalışıyor. Kodu da değiştirmelisin, biraz kafa karıştırıcıydı. –

İlgili konular