android - 如何向 Android 应用程序添加垂直平铺(仅)背景

标签 android eclipse layout background

在 Android 应用程序中水平和垂直重复线性布局的背景非常简单。您只需要使用 tileMode(参见 How to make android app's background image repeat)

但是 xml 文件中的 tileMode 不允许我仅在垂直轴上重复背景图像。有一个 tileModeY,但您无法从 xml 访问它。

我正在尝试将该属性修改为“重复”。

我有一个线性布局的 main.xml 文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:id="@+id/mainMenuLayout" 
              android:orientation="vertical"
              android:gravity="center_horizontal" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent">

我在 drawable/welcomebackground.png 中有一个图像,在 drawable/welcomebackgroundpattern.xml 中还有一个图像的 xml 文件:

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

在我的 Activity 中,我试过这个:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources();
    BitmapDrawable background = (BitmapDrawable) res.getDrawable(R.drawable.welcomebackground);
    background.setTileModeY(Shader.TileMode.REPEAT);
    (new View(this)).setBackgroundResource(R.drawable.welcomebackground);
    }

但我的背景仍然是全黑的。当然,我可以从 xml 添加它,但它在 x 轴和 y 轴上重复出现。

所以我的问题很简单:如何在我的 Activity 中垂直重复“welcomebackground”图像?

最佳答案

我找到了解决方案:Android Bitmap Tile on X Only

关于android - 如何向 Android 应用程序添加垂直平铺(仅)背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5921925/

相关文章:

android - 滚动时ListView背景变黑

android - 如何在 CardView 的自定义形状中隐藏阴影?

android - 在表面 View 上覆盖 Android 布局

android - 使用 eclipse 在 Android 中快速构建

c++ - Eclipse CDT 无法解析模板类中的方法

java - 如何将图标作为类路径资源添加到使用 WindowBuilder 创建的 SWT 窗口?

Android - 具有右对齐 View 的椭圆大小

java - Android Volley 从 onResponse 问题中获取响应

java - 将 JComponents 与 JPanel 的左侧和右侧对齐

java - 如何垂直对齐100%宽度?