【问题标题】:Android: how to create a background from pattern?Android:如何从图案创建背景?
【发布时间】:2009-11-09 10:02:59
【问题描述】:

我有一个图案(.png 图像 4x4px)并且必须用它填充布局。

有人知道怎么做吗?

如果我只是选择可绘制对象作为图像的背景,它会被拉伸;相反,它需要沿 x 和 y 轴重复。

【问题讨论】:

    标签: android background design-patterns


    【解决方案1】:

    Here 是一个非常好的解释:

    将“back.png”图像放在“drawable”文件夹中。然后像这样创建一个可绘制的“backrepeat.xml”:

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/back" 
        android:tileMode="repeat" /> 
    

    在你的布局中,添加android:background="@drawable/backrepeat":

    <?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">
    
    </LinearLayout>
    

    与许多 Android 良好做法/实用技巧一样,它可以追溯到 Romain Guy。

    【讨论】:

    • 但对我来说它只能在 android studio 的预览模式下工作
    • 如何在布局中添加圆角以及重复背景?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-01
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    相关资源
    最近更新 更多