RelativeLayout背景图像未填充其布局

时间:2016-03-22 10:07:22

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

这就是它的表现---

enter image description here

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" />

它不起作用......

感谢帮助,谢谢......

4 个答案:

答案 0 :(得分:1)

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

其次,我尝试过你的代码,然后用一种颜色替换了你的background_poly图像,它填满了整个相对布局。也许,你的图像里面有一个填充,不允许它覆盖整个布局。在Photoshop等图像编辑工具中编辑图像。

答案 1 :(得分:1)

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

答案 2 :(得分:0)

mipmap主要用于app图标。您需要将图像资源放入可绘制文件夹并更改相对布局高度以匹配父

android:layout_height="match_parent"

答案 3 :(得分:0)

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

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

并从图片中移除透明度。