【问题标题】:RelativeLayout Background Image is not Filling its LayoutRelativeLayout 背景图像未填充其布局
【发布时间】:2016-03-22 10:07:21
【问题描述】:

它是这样显示的---

XML如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="178dp"
    android:orientation="vertical"
    android:background="@mipmap/background_poly"
    android:scaleType="fitXY"
    android:weightSum="1">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:orientation="vertical"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:textColor="#ffffff"
        android:text="Xxxxx Xxxx"
        android:textSize="14sp"
        android:textStyle="bold"

        />

    <TextView
        android:id="@+id/email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="5dp"
        android:text="xxxxxxxx@xxxx.com"
        android:textSize="14sp"
        android:textStyle="normal"

        />
</LinearLayout>

<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@mipmap/aka"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="38dp"
    android:id="@+id/circleView"
    />
</RelativeLayout>

我希望背景图片完全填满相关布局。

我尝试将 scaleType 用于 **fitXY 、 center_crop ** 等

我什至尝试将 ImageView 添加到 RelativeLayout 并将其设置如下

<ImageView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop"
        android:src="@drawable/background" />

没用……

感谢您的帮助,谢谢...

【问题讨论】:

  • 你的背景图片是什么?蓝色的?

标签: android xml android-layout android-image android-relativelayout


【解决方案1】:

这是你的背景图片问题。因为背景图像在边界处包含透明度。 从边框移除透明阴影效果或更改图像,您的问题将解决。

【讨论】:

  • 我认为通过 android studio 导入图像时,它只需为其添加透明边框。但我希望将图像从 android studio 导入到 drawable 中。这可能吗??
  • Android studio 无法更改图片效果。您可以将图像导入到drawable中,只需将图像粘贴到drawable中
【解决方案2】:

首先,不要将 mipmap 文件夹用于启动器图标以外的任何图标或图像。将所有其他图标或图像放在它们各自的可绘制文件夹中。

其次,我尝试了您的代码,并用颜色替换了您的 background_poly 图像,它填充了整个相对布局。也许,您的图像内部包含一个填充,它不允许它覆盖整个布局。在 Photoshop 等图像编辑工具中编辑您的图像。

【讨论】:

  • 那么如何将android studio 1.5中的图像导入drawable文件夹。当导入为 New->Image Asses->Launcher Icon 时,它位于 mipmap 文件夹中,如果使用 New->Image Asset->Action Bar 或 Tab Icon 导入,它落在 drawable 上,但只导入了一个空白的白色图像,我没有这么认为我应该使用 New->Image Asset->Notification icon。
  • 您的启动器图标应仅位于 mipmap 文件夹中。但是看看你上面的 xml 代码,相对布局的背景存在于 mipmap 文件夹中。它应该存在于可绘制文件夹中。
  • 你是对的。但是如何将图像导入可绘制文件夹...?
  • 如果您的笔记本电脑或计算机上有图像,只需将其复制并粘贴到可绘制文件夹中即可。最初,默认情况下不添加可绘制文件夹。你必须将它们添加到 res 文件夹中,每个 drawable 文件夹针对 Android 系统的不同密度包
  • 如drawable-ldli、drawable-mdpi等,然后根据每个包的密度添加规格的图片文件。
【解决方案3】:

mipmap 基本上用于应用程序图标。您需要将图像资源放入可绘制文件夹并更改相对布局高度以匹配父级

android:layout_height="match_parent"

【讨论】:

    【解决方案4】:

    首先将 layoutHeight 更改为 android:layout_height="match_parent"

    然后将 图像 scaleType 更改为 android:scaleType="fitXY"

    并且还可以移除图像中的透明度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-28
      • 2016-02-12
      • 2019-01-28
      • 2012-04-06
      • 2014-08-01
      • 1970-01-01
      相关资源
      最近更新 更多