Android 平铺位图 [英] Android Tile Bitmap

查看:17
本文介绍了Android 平铺位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Android 中加载我想要平铺的位图.我目前在视图中使用以下内容来显示位图:

I'm trying to load a bitmap in Android which I want to tile. I'm currently using the following in my view to display a bitmap:

canvas.drawBitmap(bitmap, srcRect, destRect, null)

我本质上想将此位图用作我的应用程序中的背景图像,并希望在 X 和 Y 方向上重复该位图.

I essentially want to use this bitmap as a background image in my app and would like to repeat the bitmap in both the X and Y directions.

我已经看到了 BitmapShader 类的 TileMode.REPEAT 常量,但我不确定它是用于重复实际位图还是用于将过滤器应用于位图.

I've seen the TileMode.REPEAT constant for the BitmapShader class but i am not sure if this is to be used for repeating the actual bitmap or is used for applying a filter to the bitmap.

推荐答案

您可以在 xml 而不是 java 代码中执行此操作.我自己没有尝试过,但我确实找到了这个例子.

You would do this in the xml instead of the java code. I haven't attempted this myself but I did find this example.

<xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat"
>

然后在一个名为 backrepeat.xml 的 xml 中

then in an xml called backrepeat.xml

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

参考

这篇关于Android 平铺位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆