我正在从互联网下载位图,然后将该位图作为Drawable将其设置为LinearLayout中的背景。将Drawable调整为全屏
我看到不幸的是图像被缩放以填充视图,我如何缩放图像直到最小的尺寸到达边界(所以它不被拉伸)? (并可能居中)
我试过类似的东西,但没有任何成功。 我在路上吗?
LinearLayout layout = (LinearLayout) context.findViewById(R.id.main);
Drawable picture = new BitmapDrawable(context.getResources(), bitmap);
Display display = context.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
picture.setBounds(0, 0, size.x, size.y);
layout.setBackgroundDrawable(picture);
是的,但我的形象是不是一个ImageView的,但被设置为在后台LinearLayout中。你知道我是否可以将ImageView放在背景上(并将其放在其他视图上)? – Enrichman
嗯......这么想。我真的很喜欢使用相对布局(他们都是关于自由的))。将ImageView设置为背景并使用CENTER_CROP是一种解决方案。但我想不到在LinearLayout中做到这一点的方法(如果可能的话)。 –