2011-12-04 51 views
2

我有一個PreferenceActivity與兩個複選框。一切工作正常,但我有一個UI問題;並非複選框的所有文本都適合複選框行。Android PreferenceActivity項目高度

有沒有一種很好的方式來設置這些複選框首選項的最低高度,而不需要硬編碼值?

編輯 - 添加XML:

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen 
xmlns:android="http://schemas.android.com/apk/res/android"> 
    <CheckBoxPreference 
     android:key="alarm_set" 
     android:title="@string/set_alarm_title" 
     android:defaultValue="true" /> 
    <CheckBoxPreference 
     android:key="store_pages" 
     android:title="@string/store_downloaded_pages_title" 
     android:summary="@string/store_downloaded_pages" 
     android:defaultValue="false" /> 
</PreferenceScreen> 
+0

展我們的PreferenceActivity的XML如果你想要一個比以下猜測更具體的答案 – Blundell

+0

我會將它添加到問題中,因爲它顯示的比o好n評論 – barry

+0

是的,你必須制定像iFor這樣的自定義偏好。所有你需要做的就是控制摘要文本,如果你去找到它可能被設置爲maxLines 1的源,那就是爲什麼你的文本沒有顯示。 – Blundell

回答

4

基於關閉大約有我使用這個類相同iussue文本首選this問題。

public class LongSummaryCheckBoxPreference extends CheckBoxPreference 
{ 
    public LongSummaryCheckBoxPreference(Context ctx, AttributeSet attrs, int defStyle) 
    { 
     super(ctx, attrs, defStyle);   
    } 

    public LongSummaryCheckBoxPreference(Context ctx, AttributeSet attrs) 
    { 
     super(ctx, attrs); 
    } 

    @Override 
    protected void onBindView(View view) 
    {   
     super.onBindView(view); 

     TextView summary= (TextView)view.findViewById(android.R.id.summary); 
     summary.setMaxLines(4); 
    }   
} 

在xml中它看起來像這樣。

<com.iforpowell.android.ipbike.LongSummaryCheckBoxPreference android:key="@string/key_distance_line_enable" 
     android:title="@string/title_distance_line_enable" android:summary="@string/summary_distance_line_enable" 
     android:defaultValue="true" /> 
    <com.iforpowell.android.ipbike.LongSummaryCheckBoxPreference android:key="@string/key_altitude_line_enable" 
     android:title="@string/title_altitude_line_enable" android:summary="@string/summary_altitude_line_enable" 
     android:defaultValue="true" /> 

我有完全的EditTextPreference一樣的東西其中有2線摘要一個最大的相同的問題在阿比< = 7

+0

它仍然使用硬編碼值 - setMaxLines(4)。我想可以設置MaxLines(20)以確保不會有任何裁剪,但是你知道是否有方法讓容器「適應」文本? – barry

+0

好吧setMaxLines只要比以往任何時候都要填滿需要的東西,你不會得到4,所有時間只有4個,所以如果你真的想把它設置爲MAX_INT。 – Ifor

+0

感謝您的幫助。賞金頒發和聖誕快樂! – barry

0

在XML中,你可以將高度設置爲「WRAP_CONTENT」 。在這一點上,它會調整大小以適應你放入的任何東西。因此,這些方針的東西:

<CheckBox 
    android:id="@+id/checkBox1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="CheckBox" /> 
+0

對不起 - 這不行。 – barry

0

這應該有助於

只要做到這一點是這樣的:

<!-- Application theme --> 
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> 
    <!-- Min item height --> 
    <item name="android:listPreferredItemHeight">10dp</item> 
</style> 

可以覆蓋可以在這裏找到另一造型屬性preference item layout