I believe ListView just uses whatever padding the selector drawable reports.
 The first thing, then, is to verify there isn't a problem in your drawable.
 Write a little code that retrieves the resource, calls
Drawable.getPadding() to retrieve the padding, and see what you get.  That
will isolate the problem either to something in list view or the drawable.

Also I'm not clear on where the 9-patch is adding extra padding, but as far
as I know it will only add padding around the entire contents of the list
(that is in addition to the padding on the ListView itself), not to
individual items.

I'd also recommend you explicitly set the padding on your graphic instead of
leaving it empty.  That is, if you don't want the selection to extend
outside of the list item at all, fill the entire right and bottom rows with
black pixels; the black pixels indicate where the list item content should
be positioned within the overall selector graphic.  This is how the standard
list selector is designed, for example:

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob_plain;f=core/res/res/drawable-hdpi/list_selector_background_focus.9.png;hb=HEAD

On Tue, Apr 5, 2011 at 4:12 PM, jsera <gall.blad...@gmail.com> wrote:

> That extra area is transparent pixels, and they are there by design.
> They do not define stretchable areas, and the framework pays no
> attention to them.
>
> I'm using the draw9patch app that comes with the Android tools. I'm
> dragging a completely standard png into the tool, which is outputting
> a 9 patch that is exactly what the OS is expecting. I'm not editing
> the resulting 9 patch myself at all. I'm relying entirely on the
> provided tools.
>
> --
>
> Here's the situation I'm trying to solve:
>
> I have an item in a list that looks abstractly like this:
>
> http://www.yourmomsa.com/misc/sampleItem.png
>
> The code looks like this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout
>        xmlns:android="http://schemas.android.com/apk/res/android";
>         android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>        android:paddingLeft="8dip"
>        android:paddingRight="8dip"
>        android:paddingTop="3dip"
>        android:paddingBottom="2dip"
>        android:gravity="center">
>        <RelativeLayout
>                 android:layout_width="fill_parent"
>                 android:layout_height="wrap_content"
>                android:background="@drawable/list_raft"
>                android:padding="8dip">
>                <TextView
>                        android:id="@+id/itemHeadline"
>                         android:layout_width="fill_parent"
>                         android:layout_height="wrap_content"
>                        android:textSize="16dip"
>                        android:textColor="#000"
>                        android:textStyle="bold"/>
>                <TextView
>                        android:id="@+id/itemDate"
>                        android:layout_width="wrap_content"
>                        android:layout_height="wrap_content"
>                        android:layout_below="@+id/itemHeadline"
>                        android:text="January 86th, 1056 25:66 ZM"
>                        android:textColor="#838383"
>                        android:textSize="14dip"/>
>        </RelativeLayout>
> </LinearLayout>
>
> The gray area would be the LinearLayout, the blue would be the
> RelativeLayout.
>
> The item can be variable height, and when a list item is tapped, I
> want the overlay to be only over the blue part, or the RelativeLayout.
> Since the padding of the LinearLayout is constant, this would seem to
> be the perfect situation for a 9 patch.
>
>
> BBB  U  U TTTTT    N   N  OOOO
> B  B U  U   T      NN  N O    O
> BBB  U  U   T      N N N O    O
> B  B U  U   T      N  NN O    O
> BBB   UU    T      N   N  OOOO
>
> Because the bloody 9 patch is adding Extra padding and making me very
> grumpy which all my long-suffering co-workers don't like.
>
>
>
>
>
>
> On Apr 5, 3:32 pm, Justin Anderson <magouyaw...@gmail.com> wrote:
> > From the Dev Guide on 9-Patch drawables (
> http://developer.android.com/guide/topics/graphics/2d-graphics.html#n...
> > ):
> > *"A NinePatch drawable is a standard PNG image that includes an extra
> > 1-pixel-wide border. It must be saved with the extension .9.png, and
> saved
> > into the res/drawable/ directory of your project."
> > *
> > From the image you supplied it looks like you have much more than 1 extra
> > pixel to define the stretchable areas...  That very well could be the
> cause
> > of your padding
> >
> > Thanks,
> > Justin Anderson
> > MagouyaWare Developerhttp://sites.google.com/site/magouyaware
> >
> > On Tue, Apr 5, 2011 at 3:35 PM, jsera <gall.blad...@gmail.com> wrote:
> > > It looks like this:
> >
> > >http://www.yourmomsa.com/misc/screenshot.png
> >
> > > On Apr 5, 2:03 pm, Justin Anderson <magouyaw...@gmail.com> wrote:
> > > > What does your 9 patch look like?
> >
> > > > Thanks,
> > > > Justin Anderson
> > > > MagouyaWare Developerhttp://sites.google.com/site/magouyaware
> >
> > > > On Tue, Apr 5, 2011 at 2:27 PM, jsera <gall.blad...@gmail.com>
> wrote:
> > > > > <ListView
> > > > >                android:id="@+id/mainList"
> > > > >                android:layout_width="fill_parent"
> > > > >                android:layout_height="fill_parent"
> > > > >                android:layout_below="@+id/topNav"
> > > > >                android:layout_above="@+id/zgallery"
> > > > >                android:cacheColorHint="#FFF"
> > > > >                android:divider="@null"
> > > > >                android:drawSelectorOnTop="true"
> > > > >                android:listSelector="@drawable/list_selected"/>
> >
> > > > > That's 100% it. The selector is a 9-patch called
> list_selected.9.png.
> >
> > > > > With the last two attributes, and a 9-patch, I get extra padding.
> > > > > Without the last two attributes, I don't get extra padding.
> >
> > > > > On Apr 5, 12:01 pm, Justin Anderson <magouyaw...@gmail.com> wrote:
> > > > > > Without showing us what you are doing exactly (i.e. some code),
> you
> > > > > aren't
> > > > > > going to get a good answer.
> >
> > > > > > Thanks,
> > > > > > Justin Anderson
> > > > > > MagouyaWare Developerhttp://sites.google.com/site/magouyaware
> >
> > > > > > On Tue, Apr 5, 2011 at 11:37 AM, jsera <gall.blad...@gmail.com>
> > > wrote:
> > > > > > > I don't want this. How do I prevent the 9 patch from adding
> padding
> > > to
> > > > > > > the ListView.
> >
> > > > > > > I have NO, repeat, NO pixels on the bottom, or the right hand
> side,
> > > > > > > which the docs say add padding. They are not there.
> >
> > > > > > > --
> > > > > > > You received this message because you are subscribed to the
> Google
> > > > > > > Groups "Android Developers" group.
> > > > > > > To post to this group, send email to
> > > > > android-developers@googlegroups.com
> > > > > > > To unsubscribe from this group, send email to
> > > > > > > android-developers+unsubscr...@googlegroups.com
> > > > > > > For more options, visit this group at
> > > > > > >http://groups.google.com/group/android-developers?hl=en
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > > > Groups "Android Developers" group.
> > > > > To post to this group, send email to
> > > android-developers@googlegroups.com
> > > > > To unsubscribe from this group, send email to
> > > > > android-developers+unsubscr...@googlegroups.com
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/android-developers?hl=en
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to
> android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
> >
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to