[英]How can I draw a tiled background image with “ends” on Android?
I want to create a bookshelf that tiles horizontally and vertically. 我想创建一个水平和垂直平铺的书架。 I have three images, ShelfLeft, ShelfMid, and ShelfRight. 我有三个图像,ShelfLeft,ShelfMid和ShelfRight。 ShelfLeft starts each row/shelf, followed by X ShelfMids across the screen, capped off by ShelfRight at the end of each row. ShelfLeft从每一行/架子开始,然后在屏幕上依次显示X个ShelfMid,在每一行的末尾都有ShelfRight限制。
There will be a default of 5 rows, and if more are needed, they shall be able to be added dynamically. 默认为5行,如果需要更多行,则应能够动态添加它们。
What is the best way to go about doing this? 这样做的最佳方法是什么?
Thanks. 谢谢。
I'd use a TableLayout
. 我会使用TableLayout
。 Use a cell for each of the "ends", and then another single cell for the tiled background. 为每个“端点”使用一个单元格,然后为平铺背景使用另一个单个单元格。
To make a background repeat, create res/drawable/my_background.xml: 要重复背景,请创建res / drawable / my_background.xml:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/back"
android:tileMode="repeat" />
Then reference this as the background in your layout by specifying `android:background="@drawable/my_background". 然后通过指定`android:background =“ @ drawable / my_background”将其作为布局中的背景。
(Source: http://androidblogger.blogspot.com/2009/01/how-to-have-tiled-background-cont.html ) (来源: http : //androidblogger.blogspot.com/2009/01/how-to-have-tiled-background-cont.html )
Also worth noting: You might find the NinePatch
class useful when creating your "ends". 同样值得注意的是:您可能会发现NinePatch
类在创建“端点”时很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.