我正在尝试将背景上的图像平铺,直到背景填满。
我当前的代码是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/cartoonclouds"
android:contentDescription="@string/desc"
android:tileMode="repeat" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
</RelativeLayout>
然而,这只是使图像从下到上覆盖(而不是平铺),而不是从左到右。我应该做什么?
编辑:尝试了 XML 版本:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:tileMode="repeat"
android:src="@drawable/cartoonclouds" />
main.xml 可以在与该 XML 文件相同的文件夹中找到卡通云,但找不到该 XML 文件。
首先,将图像放入 res/drawable/cloud.png 等文件中。这使得您的应用程序可以将其作为 @drawable/cloud 进行访问。但它还没有平铺。
接下来,您应该使用 android:tileMode="repeat" 定义位图资源(1)。例如,您可以在 mytileablebitmap.xml 上定义它:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:tileMode="repeat"
android:src="@drawable/cloud"/>
这是引用您的原始平铺图像(可绘制/云)并制作一个知道如何平铺自身以填充可用空间的可绘制对象。
然后,当您想使用平铺背景时,请使用“@drawable/mytileablebitmap”。
(1): http://developer.android.com/guide/topics/resources/drawable-resource.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)