Android以编程方式拉伸背景图像
我正在使用从internet下载的图像作为我的一项活动的背景。但我的问题是,我想以编程方式拉伸图像,使其适合任何分辨率。我用于将图像设置为RelativeLayout的背景的代码如下:Android以编程方式拉伸背景图像,android,image,background,Android,Image,Background,我正在使用从internet下载的图像作为我的一项活动的背景。但我的问题是,我想以编程方式拉伸图像,使其适合任何分辨率。我用于将图像设置为RelativeLayout的背景的代码如下: BitmapFactory.Options options = new BitmapFactory.Options(); options.inTempStorage = new byte[4*1024]; Bitmap ops = BitmapFactory.decodeFile(pat
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[4*1024];
Bitmap ops = BitmapFactory.decodeFile(path, options);
BitmapDrawable bitmapDrawable = new BitmapDrawable(ops);
layoutBG.setBackgroundDrawable(bitmapDrawable);
那么,我该如何设置图像拉伸呢?检查您的
xml
文件中是否有任何填充或边距
,因为如果您的相对框中有边距
图像将不会拉伸整个布局。您现在感觉如何?layoutBG来自哪里?您是否从布局XML中获取它?通常,如果将背景设置为视图,则背景会拉伸到视图的大小。也许您需要确保视图覆盖整个屏幕?我从xml文件获取布局,并将其参数设置为fill\u parent
,但背景没有拉伸高度。实际上,我刚刚看到我有marginBottom
。谢谢你的回答!