Android图像背景重复

tin*_*nti 13 android background-image repeat

我有一个用于LinearLayout背景的图像让我们说图像有20x100像素我想让图像只在x轴上重复...在css中这样的东西

background-repeat:repeat-x;
Run Code Online (Sandbox Code Playgroud)

LinearLayout有点大(1024 x 680像素),所以我的图像将覆盖整个宽度,但只在顶部(其余580像素的高度将是透明的)我希望我很清楚谢谢

Zeb*_*eba 55

尝试使用android:tileMode

background.xml在drawable文件夹中创建:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
  android:src="@drawable/bg" 
  android:tileMode="repeat" />  
Run Code Online (Sandbox Code Playgroud)

然后在你的布局xml中使用它:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >
Run Code Online (Sandbox Code Playgroud)

  • @Sirlate请检查以上编辑的解决方案. (3认同)
  • 这应该是接受的答案!! (2认同)

Dav*_*555 0

您可以使用 android:background 作为 9patch 图像来自动拉伸。

Android 开发网站上的 9patch

  • 这不是问题的答案。 (6认同)