Android 将可绘制图像调整为全屏
我正在从internet下载一个位图,然后将此位图转换为可绘制位图,以将其设置为LinearLayout中的背景 我看到不幸的是,图像被缩放以填充视图,如何缩放图像直到最小尺寸到达边界(因此它不会拉伸)? (并且可能居中) 我试过这样的方法,但没有成功。 我在路上吗Android 将可绘制图像调整为全屏,android,background,drawable,android-linearlayout,Android,Background,Drawable,Android Linearlayout,我正在从internet下载一个位图,然后将此位图转换为可绘制位图,以将其设置为LinearLayout中的背景 我看到不幸的是,图像被缩放以填充视图,如何缩放图像直到最小尺寸到达边界(因此它不会拉伸)? (并且可能居中) 我试过这样的方法,但没有成功。 我在路上吗 LinearLayout layout = (LinearLayout) context.findViewById(R.id.main); Drawable picture = new BitmapD
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);
我想你需要这样的东西
setScaleType(ScaleType.CENTER_CROP);
请看我认为,在应用程序上使用缩放图像是不可取的。最好使用重复模式。所以,我想试试这样的方法:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background-image-repeatable-pattern.png"
android:tileMode="repeat" />
将其保存到drawable/background.xml文件(例如)是,但我的图像不在ImageView中,而是在LinearLayout中设置为背景。你知道我是否可以在背景上放一个图像视图(以及其他视图)?嗯。。。我想是的。我真的很喜欢使用相对布局(它们都是关于自由的)。将ImageView设置为背景并与CENTER_裁剪一起使用是一种解决方案。但我想不出一种在线性布局中实现这一点的方法(如果可能的话)。