Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android以编程方式拉伸背景图像_Android_Image_Background - Fatal编程技术网

Android以编程方式拉伸背景图像

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

我正在使用从internet下载的图像作为我的一项活动的背景。但我的问题是,我想以编程方式拉伸图像,使其适合任何分辨率。我用于将图像设置为RelativeLayout的背景的代码如下:

    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
。谢谢你的回答!