Difference between src and background for image view [duplicate]

让人想犯罪 __ 提交于 2019-12-04 06:54:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!