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?
Wrap your
ImageViewin aFrameLayout, and define theFrameLayoutto be clickable. Be careful to assign the onClick event to theFrameLayout, and not to theImageView, or the effect will break! Also note thatforegroundhas been set to a selector, notbackground.