【发布时间】:2013-08-23 22:36:59
【问题描述】:
如何在不拉伸图像的情况下将 LinearLayout 的背景设置为特定图像(从 Internet 获取)?
基本上,我有以下代码将 Bitmap 转换为 BitmapDrawable,这反过来又允许我以编程方式设置 LinearLayout 的背景:
BitmapDrawable myBackground = new BitmapDrawable(myBitmap);
myLinearLayout.setBackgroundDrawable(myBackground);
问题是,图像拉伸以匹配 LinearLayout 的高度和宽度;它不会像我在 XML 布局中将背景设置为可绘制那样水平和垂直居中。如何使用从 Internet 检索的位图实现此目的?
【问题讨论】:
-
尽量不要改变背景层,用于
ImageView。如何设置图片大小:image_view.getLayoutParams().height = 50;,image_view.getLayoutParams().width = 50;
标签: android