Search code examples
androidgridviewandroid-gallery

Android GridView selected item border/highlight


In the native Gallery app on Android, when Select item via Option Menu action, you can select multiple items, each grid item which will have a colored-border overlay on top signify as selected when clicked.

Question:

  • How to do this dynamically using getView() in the ImageAdapter class? (since there is setBackgroundColor() but not setBorder()

  • Is there a better way to accomplish this? (such as creating a padding of some sort for the image within the gridview cell, then set the background color which will look like a border)


Solution

    • I finally decided to use the 2nd method in the original post: creating a padding for ImageView within the gridview cell and set the background color.
    • I used ImageView.ScaleType.CENTER_CROP with setCropToPadding(true); for the ImageView.