SectionIndexer personalizado para Android listivew. ¡El índice mostrado no cabe en el fondo transparente!

For my listview in android, I am using a custom baseadapter which creates the date separated headers between the items of the list. FastSctoll is enabled on the listview and this adapter also implements SectionIndexer to display short dates (e.g Feb 14) as indexes when doing scrolling using thumb-scroller. It works fine, except that transparent background behind these displayed indexes does not fully cover the short dates. It ends up luciendo así.

Can the font of the displayed index be made smaller or the background stretched to make the date fully appear within the background image??

preguntado el 08 de enero de 11 a las 23:01

2 Respuestas

I was able to resolve the same problem by overriding the FastScroller's paint member using this url as the inspiration customize fastScroller(change overlay and scroller) for Android

Although you don't need to create a new instance just to modify the paint.

KitKat update: This is not needed for KitKat because they now handle longer text lengths correctly. You should condition this code for API's <= 18 only.

AbsListView listview = (AbsListView) findViewById(..);
try {
    Field fieldFastScroller = AbsListView.class.getDeclaredField("mFastScroller");
    fieldFastScroller.setAccessible(true);
    Object fastScroller = fieldFastScroller.get(listview);

    Field fieldPaint = fastScroller.getClass().getDeclaredField("mPaint");
    fieldPaint.setAccessible(true);
    Paint paint = (Paint)fieldPaint.get(fastScroller);
    // make the text half the normal fastscroller size 
    // to make room for a short date "MMM dd"
    paint.setTextSize( paint.getTextSize() / 2 );

    fieldPaint.set(fastScroller, paint);

} catch (Exception e){
    e.printStackTrace();
}

Respondido el 14 de enero de 14 a las 01:01

Check for the FastScroller.java Android source file, it is the class which draw the overlay.

Respondido 16 Feb 11, 11:02

You can find FastScroller.java by searching the android code base here: codesearch.google.com/… - dgmltn

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.