2011-12-04 36 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