我正在尝试将一张图片作为背景平铺,直到整个背景都被填满。
我的当前代码如下:
<?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可以在与同一文件夹内查找cartoonclouds,但无法找到该XML文件。
@drawable/cloud
,但不能识别@drawable/mytileablebitmap
,尽管这两个都存在,一个是.jpg格式,一个是.xml格式。(在XML文件中给我报错) - user938787ScaleType
设置为fitXY
。我还更改了位图可绘制对象——在需要沿Y轴平铺的地方,将android:gravity
设置为fill_vertical
,在需要沿X轴平铺的地方,将其设置为fill_horizontal
。这可能会对某些人有所帮助。 - JWL