问题
I have two imageviews. I have set background for one image view and I have set src for one image view . But both are looking differnt and also when i press the imageview with background set it is not showing the selection. can anyone explain why this happens ?
<ImageButton android:layout_width="250dp"
android:layout_height="100dp"
android:background="@drawable/perm_group_camera"/>
<ImageButton android:layout_width="250dp"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:src="@drawable/perm_group_calendar"/>
回答1:
But both are looking differnt
First, the drawables are different.
Second, the background always scales to the size of the view.
when i press the imageview with background set it is not showing the selection. can anyone explain why this happens
The selection effect is because by default, the background is a StateListDrawable with a different appearance in state_pressed. Your custom background looks the same in all states. You can create StateListDrawables in xml with a selector.
回答2:
Background will fill all avaliable place of view, src - will paste image and scale/positioning using ImageView parameters. For example, parameters "scaleType", "scaleX", "scaleY", "gravity", "adjustViewBounds" will affects only on src image
来源:https://stackoverflow.com/questions/21352322/difference-between-src-and-background-for-image-view