2017-08-03 83 views
0

有框架布局,其中width \ height = wrap_content。但是,当我尝试设置背景时,它会增加到最大尺寸,即使它不包含任何元素。如何修复它?wrap_content不适用于背景

<FrameLayout 
    xmlns:android="schemas.android.com/apk/res/android"; 
    xmlns:app="schemas.android.com/apk/res-auto"; 
    android:background="@drawable/oblakol" 
    adroid:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerInParent="true" > 
    <TextView 
     android:id="@+id/textView8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TextView" /> 
</FrameLayout> 
+0

当您将其设置为wrap_content时,它会占用完整大小的背景图像。 FrameLayout的大小取决于背景图像的大小。 – Furqan

回答

2

您的背景比您想象的要大得多。检查背景大小!

0

包装内容正在工作,但您的图像尺寸很大,因此您没有得到预期的结果。 尝试导入图像为 - >图像资产,这样的大小将自动调整 或 手动设置大小!

0

我希望这将帮助你......

WRAP_CONTENT将会把它的背景是原始大小。

使用较大的分辨率会导致您的应用程序在使用时滞后。因此,您应根据自己的需要调整背景大小:Image Resizer

0

将视图的尺寸(layout_width或layout_height)设置为WRAP_CONTENT时,您可以自由扩大视图而无任何限制(根据其内容)。因为您已将帧布局的高度和宽度设置为WRAP_CONTENT,所以与您的场景一样。

所以无论屏幕上占用的空间是多少,都是由于你的大尺寸你的可绘制图像。尝试将帧布局的高度和宽度设置为一些随机值进行测试。

android:layout_width="250dp" 
android:layout_height="250dp" 

我附上了一些截图供您参考。

  1. android:layout_width和android:layout_height设置为WRAP_CONTENT。所述机器人图像实际尺寸是800x799(宽x高)

enter image description here

  • 机器人:layout_width和机器人:layout_height设置为WRAP_CONTENT。所述机器人图像实际尺寸是256×256(宽x高)
  • enter image description here

  • 机器人:layout_width和机器人:layout_height设置为250dp。 Android的图像的实际尺寸为800x799(宽x高)

    enter image description here

  • 希望它能帮助。

    相关问题