您的位置:首页 > 其它

setBackgroundResource和setImageResource有什么区别

2017-10-27 12:02 274 查看

参考

http://blog.csdn.net/dalancon/article/details/42495287

场景

imageView1.setImageResource(R.drawable.img);
imageView2.setBackgroundResource(R.drawable.img)


imageView1和imageView2是两个相同的ImageView。他们都是在同一个RelativeLayout父容器里面,RelativeLayout的android:background=”@color/transparent”,也就是父容器背景透明。

效果

imageView1



imageView2



总结

setImageResource是设置图片但不改变背景色。

而setBackgroundResource是改变背景色。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: