用位图平铺图像 xml 不起作用

Tilling a image with a bitmap xml doesn't work

这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/up_margin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/ticket_up_tile"/>

<RelativeLayout
    android:id="@+id/container"
    android:layout_below="@id/up_margin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:layout_margin="10dp">

    <TextView
        android:id="@+id/origin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/gray32"
        android:textSize="17dp"/>

    <TextView
        android:id="@+id/destination"
        android:layout_below="@id/origin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:translationY="-5dp"
        android:textColor="@color/gray32"
        android:textSize="17dp"/>

    <TextView
        android:id="@+id/title"
        android:layout_below="@id/destination"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/gray32"
        android:textSize="28dp"
        android:text="@string/intro.mileage"/>

    <View
        android:id="@+id/line1"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_below="@id/title"
        android:background="@color/gray32"/>

    <RelativeLayout
        android:layout_marginTop="10dp"
        android:layout_below="@id/line1"
        android:id="@+id/prices_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </RelativeLayout>

    <View
        android:id="@+id/line2"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_below="@id/prices_container"
        android:background="@color/gray32"/>

    <TextView
        android:id="@+id/dismiss"
        android:layout_below="@id/line2"
        android:textColor="@color/background"
        android:padding="10dp"
        android:layout_centerHorizontal="true"
        android:text="@string/Dismiss"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>
<ImageView
    android:id="@+id/down_margin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/container"
    android:src="@drawable/ticket_down_tile"/>

我在开头和结尾都有一张需要平铺的图像。 我在上面设置了一个我创建的可绘制对象:

<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:tileMode="repeat"
android:src="@drawable/popup_ticket_up"/>

如您所见,它在 Repeat 上有 tileMode。还有 imageViews,两者的宽度都与父母相匹配。 这就是我得到的:

bitmap 作为 background 设置到您的容器(或在您想要的 View 上),而不是将其作为 src 添加到 ImageView