Android首选项活动项高度

Android首选项活动项高度,android,preferenceactivity,Android,Preferenceactivity,我有一个带有两个复选框的首选项活动。一切正常,但我有一个UI问题;并非复选框的所有文本都适合复选框行 有没有一种好方法可以在不硬编码值的情况下设置这些复选框首选项的最小高度 编辑-添加xml: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <CheckBoxPreferenc

我有一个带有两个复选框的首选项活动。一切正常,但我有一个UI问题;并非复选框的所有文本都适合复选框行

有没有一种好方法可以在不硬编码值的情况下设置这些复选框首选项的最小高度

编辑-添加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>

基于关于文本首选项与我使用的类具有相同IUS的问题

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,我也有同样的问题,即Api中的摘要最多有2行,在xml中,您可以将高度设置为“wrap_content”。在这一点上,它将大小,以适应任何你放在它。因此,大致如下:

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

这应该会有所帮助

就这样做吧:

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

10dp

可以在此处找到另一个可以覆盖的样式属性

它仍然使用硬编码值-setMaxLines(4)。我想可以设置MaxLines(20)以确保永远不会出现任何裁剪,但是你知道是否有一种方法可以让容器“刚好适合”文本吗?好的,设置MaxLines,只要比以往任何时候都多,就可以填充所需的内容,你不会一直得到4个,最多4个。如果你真的想的话,把它设为MAX_INT。谢谢你的帮助。赏金获得,圣诞快乐!如果你想要一个比下面猜测更具体的答案,请向我们展示你的首选项活动的XML。我会将它添加到问题中,因为它比在评论上显示得更好。是的,你必须像iFor所展示的那样定制首选项。您所需要做的就是控制摘要文本,如果您找到源代码,它可能会设置为maxLines 1,这就是您的文本不显示的原因。