简体   繁体   English

如何在 Android 上向背景 bitmap 添加边距

[英]How can I add margin to background bitmap on Android

So I would like to create a checkered effect with my bitmap.所以我想用我的 bitmap 创建一个方格效果。 So I am using this very small pixel grey color png.所以我使用这个非常小的像素灰色png。 I need to add a margin or padding before it's repeated but I'm unsure how to do this.我需要在重复之前添加边距或填充,但我不确定如何执行此操作。 Any help will be welcome as I have just started learning Android development.欢迎任何帮助,因为我刚刚开始学习 Android 开发。

What it's doing right now is repeating the entire image, filling the window with one color.它现在正在做的是重复整个图像,用一种颜色填充 window。

Background.xml背景.xml

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

</bitmap>

In my Activity Main XML I'm including the above XML在我的活动主要 XML 我包括上述 XML

android:background="@drawable/background"

If I understand You correct and You want to make an effect like this如果我理解你是正确的并且你想产生这样的效果

在此处输入图像描述

Using a single grey pixel and adding margin to next before repeating, it will be much easier if You don't use:在重复之前使用单个灰色像素并为下一个添加边距,如果您不使用它会容易得多:

在此处输入图像描述

But just a:但只是一个:

在此处输入图像描述

With a pattern like this, You can repeat an image and You will get a checkered effect.使用这样的图案,您可以重复图像,您将获得方格效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM