Difference between src and background for image view(图像视图的 src 和背景之间的区别)
问题描述
我有两个图像视图.我为一个图像视图设置了背景,我为一个图像视图设置了 src .但是两者看起来都不一样,而且当我按下带有背景设置的图像视图时,它也没有显示选择.谁能解释为什么会这样?
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.
当我按下带有背景设置的图像视图时,它不显示选择.谁能解释为什么会发生这种情况
when i press the imageview with background set it is not showing the selection. can anyone explain why this happens
选择效果是因为默认情况下,背景是一个StateListDrawable 在 state_pressed 中具有不同的外观.您的自定义背景在所有州看起来都一样.您可以使用 在 xml 中创建 StateListDrawables选择器.
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 和背景之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:图像视图的 src 和背景之间的区别
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
