平铺在机器人图像的ImageView中XML [英] Tiling images in android with ImageView in XML
问题描述
我想,直到背景是完全获得的背景平铺图像。
I am trying to get an image on the background to tile until the background is full.
我目前的code是:
<?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>
然而,仅仅使图像覆盖(不平铺)底部到顶部,但不是从左到右。我应该怎么做?
However that just makes the image covering (not tiled) bottom to top, but NOT left to right. What should I be doing?
编辑:尝试的XML版本:
Attempted the XML version:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:tileMode="repeat"
android:src="@drawable/cartoonclouds" />
在main.xml中可以发现,在同一个文件夹的XML文件中的cartoonclouds,但无法找到该XML文件。
The main.xml could find the cartoonclouds in the SAME folder as that XML file, but could not find that XML file.
推荐答案
首先,将你的形象像RES /绘制/ cloud.png文件。这使得它可以访问你的应用程序为@可绘制/云。但它没有瓦(还)。
First, place your image in a file like res/drawable/cloud.png. This makes it accessible to your app as @drawable/cloud. But it doesn't tile (yet).
接下来,你应该定义与Android位图资源(1):TILEMODE =回头客。例如,你可以在mytileablebitmap.xml定义它:
Next, you should define a bitmap resource(1) with android:tileMode="repeat". For example, you can define it on mytileablebitmap.xml:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:tileMode="repeat"
android:src="@drawable/cloud"/>
这是引用您的原始平铺图像(绘制/云),使可绘制一个知道如何瓷砖本身以填充可用空间。
This is referencing your original tile image (drawable/cloud) and making a Drawable that knows how to tile itself to fill the available space.
然后,当你想使用平铺背景,用@绘制/ mytileablebitmap。
Then, when you want to use the tiled background, use "@drawable/mytileablebitmap".
(1):<一href="http://developer.android.com/guide/topics/resources/drawable-resource.html">http://developer.android.com/guide/topics/resources/drawable-resource.html
这篇关于平铺在机器人图像的ImageView中XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!