创建一个从图片或LT瓷砖背景;的LinearLayout> /< GridView控件>等等 [英] Create Tiled Background from Image or <LinearLayout> / <GridView> etc

查看:95
本文介绍了创建一个从图片或LT瓷砖背景;的LinearLayout> /< GridView控件>等等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,作为一个新的Andr​​oid开发者(10年以上C#OOP),这将是更好的方式来创建一个简单重复的背景。背景将是一致的,不管屏幕尺寸,密度或取向。我读过的Andr​​oid开发者开发指南的事情,如支持多个画面,九补丁可绘制等,像这样(的http://androidforbeginners.blogspot.com/2010/06/how-to-tile-background-image-in-android.html)告诉你如何使用图像,并把它重复。

I am wondering as a new Android developer (10+ years C# OOP) which would be the better way to create a simple repeating background. The background will be consistent no matter the screen size, density, or orientation. I've read the Android Developers Dev Guide about things such as supporting multiple screens, nine patch drawables etc. I have seen tutorials such as this one (http://androidforbeginners.blogspot.com/2010/06/how-to-tile-background-image-in-android.html) telling you how you can use an image and get it to repeat.

。对于复杂的背景图案,我可以看到,这可能是要走的路。但我的模式是一个简单的网格图案,从而不存在只使用XML更好的办法?

Of course using an image then you have to provide multiple images for multiple densities or risk bitmap scaling and pixelation. For a complex background pattern I can see how this might be the way to go. But my pattern is a simple grid pattern so isn't there a better way using just xml?

我看着GridView和TableLayout无一不让我设置背景颜色,指定单元格宽度/高度,但我没有看到一个方法来指定网格线的颜色。

I looked at GridView and TableLayout and both allowed me to set a background color, specify cell width / height, but I did not see a way to specify the grid line color.

现在我使用的是年龄稍大的2.3.3 API,因为这是目前正在使用的最大的版本。 我不怀疑,我需要多手holdong只是一些货真价实提醒那些谁比我更清楚。

For now I am using the slightly older 2.3.3 api as that is the largest version currently in use. I don't suspect I'll need much hand holdong just some good solid advise from those who know better than I.

感谢您 JB

推荐答案

您可以创建一个绘制这样的:

You can create a drawable like this:

<?xml version="1.0" encoding="utf-8"?>

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

代替上述在一个background.xml文件在被拉伸的文件夹。然后你可以使用它在你的布局是这样的:

Place the above in a "background.xml" file at the drawable folder. Then you can use it in your layout like this:

<RelativeLayout 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/background">

您可以使用背景与所有布局。

You can use a background with all Layouts.

我不认为有是一个不折不扣的开箱即用的方式做一个备用的重复,如表明在一些地方一个图像,另一个在另外一些国家。如果你想这样的事情,那么你很可能需要实现自己的视图,并覆盖的OnDraw方法。你可以使用一个的FrameLayout 以这样的背景下查看合并与任何其他元素。

I don't think there is an out-of-the-box way to do an alternate repeat, e.g. show one image at some places and another one in some others. If you want something like this, then you would probably need to implement your own View and override the onDraw method. You could use a FrameLayout to combine this background View with any other elements.

这篇关于创建一个从图片或LT瓷砖背景;的LinearLayout&GT; /&LT; GridView控件&GT;等等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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