Question

I'm trying to use Etsy's Staggered Gridview (https://github.com/maurycyw/StaggeredGridView), and I have it working mostly as expected, except I'm having an issue trying to get the selector to draw on top.

I've tried using mGridView.setDrawSelectorOnTop( true ); and android:drawSelectorOnTop="true" in the layout, but no success yet. Anyone happen to have solved this problem, or know if it's not possible with the library in its current state?

Was it helpful?

Solution

Etsy's StaggeredGrid frustratingly doesn't support item selector drawables. To work around this, set the selector on the GridView item, not the GridView itself.

In my current project, I wrap the GridView item in a FrameLayout, because a FrameLayout has an android:foreground attribute:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:foreground="?android:attr/selectableItemBackground">

    <!-- Your item layout goes here. -->

</FrameLayout>

?android:attr/selectableItemBackground gives you the standard blue highlight. If you want, you can use your own state list drawable instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top