图像视图的src和背景之间的差异 [英] Difference between src and background for image view
问题描述
我有两张图片。我为一个图像视图设置了背景,我为一个图像视图设置了src。但两者看起来都不一样,当我按下带有背景设置的imageview时,它也没有显示选择。谁能解释为什么会这样?
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"/>
推荐答案
但两者看起来不同
But both are looking differnt
首先,drawables是不同的。
First, the drawables are different.
其次,背景总是缩放到大小视图。
Second, the background always scales to the size of the view.
当我按下背景设置的imageview时,它没有显示选择。任何人都可以解释为什么会发生这种情况
when i press the imageview with background set it is not showing the selection. can anyone explain why this happens
选择效果是因为默认情况下,背景是 StateListDrawable
在<$ c中具有不同的外观$ C> state_pressed 。您的自定义背景在所有状态下看起来都相同。您可以使用 StateListDrawables rel =nofollow> 选择器
。
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
.
这篇关于图像视图的src和背景之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!