图像视图的 src 和背景之间的区别 [英] Difference between src and background for image view

查看:21
本文介绍了图像视图的 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

选择效果是因为默认情况下,背景是一个StateListDrawablestate_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 和背景之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆