Show transparent color highlight on a View when clicking it
android
Solution
Wrap your `ImageView` in a `FrameLayout`, and define the `FrameLayout` to be clickable. Be careful to assign the onClick event to the `FrameLayout`, and not to the `ImageView`, or the effect will break! Also note that `foreground` has been set to a selector, not `background`.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="@drawable/imagebutton_selector" >
<ImageView
android:id="@+id/painting_image"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="centerCrop" />
</FrameLayout>
Problem
So. You know how when you click a post in the Google+ app, the entire View becomes blue. I want to do that as well, but with an ImageView. I have the following code snippet, setting the actual image as the background and the selector as the main resource. This looks good, but doesn't respect scaleType for the background image: ``` <ImageView android:id="@+id/painting_image" android:layout_width="match_parent" android:layout_height="200dp" android:background="@drawable/img" android:src="@drawable/selector" android:scaleType="centerCrop" /> ``` By the way, `@drawable/selector` is just a selector that shows a tranparent color for `state_pressed`: ``` <item android:state_pressed="true"> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#44521400" /> </shape></item> ``` How can I make this work while respecting the scaleType?