2

I have a PreferenceActivity with two checkboxes. Everything is working correctly, but I have a UI problem; not all of the text for the checkbox fits onto the checkbox row.

Is there a nice way to set the minimum height for these checkbox preferences without hardcoding a value?

EDIT - adding 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>
barry
  • 4,037
  • 6
  • 41
  • 68
  • Show us the XML of your PreferenceActivity if you want a more specific answer than the guesses below – Blundell Dec 21 '11 at 18:30
  • I'll add it to the question as it displays better than on a comment – barry Dec 21 '11 at 19:19
  • Yeah you'll have to make a custom preference like iFor is showing. All you need to do is take control of the summary text, if you go find the source it may be set to maxLines 1, thats why your text isn't showing. – Blundell Dec 21 '11 at 19:28

3 Answers3

5

Based off this question about text preference having the same iussue I use this class.

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); 
    }        
} 

In the xml it then looks like this.

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

I have exactly the same thing for EditTextPreference which has the same problem of a max of 2 lines for the summary in Api <= 7

Community
  • 1
  • 1
Ifor
  • 2,825
  • 1
  • 22
  • 25
  • It still uses a hard-coded value though - setMaxLines(4). I suppose one could setMaxLines(20) to ensure there would never be any cropping, but do you know if there is a method to get the container to 'just fit' the text? – barry Dec 19 '11 at 20:11
  • Well setMaxLines so long as more than you ever have will just fill what is needed you don't get 4 all the time, just a max of 4. So set it to MAX_INT if you realy want to. – Ifor Dec 20 '11 at 16:33
  • Thanks for your help. Bounty awarded and Merry Xmas! – barry Dec 24 '11 at 13:06
0

This should help

Just do it this way:

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

another styling attributes that can be overridden can be found here preference item layout

Nikolay Nikiforchuk
  • 1,998
  • 24
  • 20
0

In the xml you can set the height to "wrap_content". At that point it will size it to fit whatever you put in it. So, something along these lines:

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />
Wookie1120
  • 194
  • 1
  • 11