图像视图的 src 和背景之间的区别

Difference between src and background for image view(图像视图的 src 和背景之间的区别)
本文介绍了图像视图的 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 和背景之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)