Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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
SetBackgroundDrawableResourceSetScaleType(android)_Android_Xml - Fatal编程技术网

SetBackgroundDrawableResourceSetScaleType(android)

SetBackgroundDrawableResourceSetScaleType(android),android,xml,Android,Xml,对不起,我的英语太差了,我只想使用getWindow()设置背景布局图像,如下所示: getWindow().setBackgroundDrawableResource(R.drawable.bg_image); 在bg\u图像中 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <

对不起,我的英语太差了,我只想使用
getWindow()
设置背景布局图像,如下所示:

getWindow().setBackgroundDrawableResource(R.drawable.bg_image);
bg\u图像中

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <bitmap

            android:src="@drawable/bg_shkaf" />
    </item>

</layer-list>


但这幅图被拉长了。如何按图片比例拉伸?

如果只将图像指定给窗口背景,我认为不能指定缩放类型

在类似的场景中,我所做的是使用子
ImageView
将布局包装在父
FrameLayout
中,该子
ImageView
采用
scaleType
属性。然后添加所有现有布局视图

例如:

<FrameLayout>
  <ImageView 
    android:src="@drawable/bg_image"
    android:scaleType="fitCenter" 
    android:layout_height="match_parent"
    android:layout_width="match_parent" />

  <!-- all of your other views here ... -->

</FrameLayout>

如果只将图像指定给窗口背景,我认为您无法指定缩放类型

在类似的场景中,我所做的是使用子
ImageView
将布局包装在父
FrameLayout
中,该子
ImageView
采用
scaleType
属性。然后添加所有现有布局视图

例如:

<FrameLayout>
  <ImageView 
    android:src="@drawable/bg_image"
    android:scaleType="fitCenter" 
    android:layout_height="match_parent"
    android:layout_width="match_parent" />

  <!-- all of your other views here ... -->

</FrameLayout>


谢谢您的回答。我使用
getWindow().setBackgroundDrawableResource(R.drawable.bg_image)如果设置FrameLayout,则出现错误
。。。。。。。。无效的可绘制标记框架布局
谢谢您的回答。我使用
getWindow().setBackgroundDrawableResource(R.drawable.bg_image)如果设置FrameLayout,则出现错误
。。。。。。。。无效的可绘制标记框架布局
谢谢您的回答。我使用
getWindow().setBackgroundDrawableResource(R.drawable.bg_image)如果设置FrameLayout,则出现错误
。。。。。。。。无效的可绘制标记框架布局