Here is a simple Gallery background that highlights the background of
the selected gallery item.  The background attribute is placed on the
gallery item xml (not the actual gallery widget xml).

- - - - my_gallery_item.xml - - - -
  android:background="@drawable/gallery_background"

- - - -  drawable/gallery_background.xml - - - -
<selector xmlns:android="http://schemas.android.com/apk/res/android";
        android:constantSize="true">
        <item android:state_focused="true"
                android:drawable="@color/galleryFocused" />
        <item android:drawable="@android:color/transparent" />
</selector>

- - - -  values/color.xml - - - -
<resources>
    <color name="galleryFocused">#FFFFCC00</color>
</resources>


On Dec 22, 11:29 pm, jotobjects <[email protected]> wrote:
> Just wondering why there is so much complexity involved in getting the
> platform Gallery background.  The SDK provides a theme that contains
> an attribute that is a drawable resource.   The theme is not a
> drawable so it can't be used in a layout as a background.  The example
> given is 
> -http://developer.android.com/resources/tutorials/views/hello-gallery....
> - with these steps -
>
>         TypedArray a =
> obtainStyledAttributes(R.styleable.HelloGallery);
>         mGalleryItemBackground = a.getResourceId(
>
> R.styleable.HelloGallery_android_galleryItemBackground, 0);
>         a.recycle();
>         setBackgroundResource(mGalleryItemBackground);
>
> where HelloGallery is a Them that includes the platform Theme
> attribute that is the actual drawable  -
>
> <resources>
>     <declare-styleable name="HelloGallery">
>         <attr name="android:galleryItemBackground" />
>     </declare-styleable>
> </resources>
>
> All you really want is drawable/gallery_item_background.xml.
> Unfortunately the very useful Gallery widget doesn't have default
> focus behavior unless you do all this.
>
> What is the benefit and/or rationale for all these layers?

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

Reply via email to