Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.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 安卓-如何在其中使用随机图像';s原始大小,作为背景_Android_Image_Layout_Background - Fatal编程技术网

Android 安卓-如何在其中使用随机图像';s原始大小,作为背景

Android 安卓-如何在其中使用随机图像';s原始大小,作为背景,android,image,layout,background,Android,Image,Layout,Background,我希望能够使用一个图像作为我的背景在一个相对的布局,没有它拉伸。我不想只将图像细节输入到XML文件中,因为我想使用不同大小的不同图像 我尝试了以下方法,但它只是拉伸了图像(我知道左、上、右和下变量的值是错误的,但我只是在其中输入了一些东西,作为测试,看看它是否对输出有任何影响,但没有。如果有,我会通过编程计算正确的值:- RelativeLayout explosionlayout = (RelativeLayout) findViewById (R.id.explosionlayout

我希望能够使用一个图像作为我的背景在一个相对的布局,没有它拉伸。我不想只将图像细节输入到XML文件中,因为我想使用不同大小的不同图像

我尝试了以下方法,但它只是拉伸了图像(我知道左、上、右和下变量的值是错误的,但我只是在其中输入了一些东西,作为测试,看看它是否对输出有任何影响,但没有。如果有,我会通过编程计算正确的值:-

    RelativeLayout explosionlayout = (RelativeLayout) findViewById (R.id.explosionlayout);

     imageAnim = (ImageView) findViewById(R.id.explosion);

   Drawable d;
   d = this.getResources().getDrawable(R.drawable.bomb);
   int left = 10; int top = 10; int right = 20; int bottom = 20;
   d.setBounds(left, top, right, bottom);
  explosionlayout.setBackgroundDrawable(d);
这显然是错误的。正确的解决方案是什么


谢谢。

将ImageView的属性设置为“中心”。

将ImageView的属性设置为“中心”。

谢谢您的回复。我尝试了以下操作:-imageAnim.setAdjustViewBounds(true);imageAnim.setScaleType(ImageView.ScaleType.center);但它只是被忽略了。我认为这与ImageView被用作背景图像这一事实有关。我确信如果我将其用作普通的前景ImageView,它会起作用。我确实尝试过imageAnim.setScaleType(ImageView.ScaleType.CENTER);自行设置,但没有运气。我遇到了完全相同的问题。将图像背景设置为颜色不会拉伸它,将背景设置为图像会拉伸它。向上投票。感谢您的回复。我尝试了以下方法:-imageAnim.setAdjustViewBounds(true);imageAnim.setScaleType(ImageView.ScaleType.CENTER);但它只是被忽略了。我认为这与ImageView被用作背景图像这一事实有关。我确信如果我将其用作普通的前景ImageView,它会起作用。我确实尝试过imageAnim.setScaleType(ImageView.ScaleType.CENTER);靠自己,但运气不好。我遇到了完全相同的问题。将图像背景设置为颜色不会拉伸它,将背景设置为图像会拉伸它。向上投票。