Android以编程方式将图像平铺为背景

Android以编程方式将图像平铺为背景,android,image,background,Android,Image,Background,我有一个图像,我想平铺水平,我需要它做编程。我试过两种方法,但都不起作用 按钮\内部\阴影是图像 导航背景是假定平铺上述图像的xml 1:直接平铺图像 BitmapDrawable navigationBackground = new BitmapDrawable(BitmapFactory.decodeResource( getResources(), R.drawable.button_inner_shadow)); navigationBackground.

我有一个图像,我想平铺水平,我需要它做编程。我试过两种方法,但都不起作用

按钮\内部\阴影是图像 导航背景是假定平铺上述图像的xml

1:直接平铺图像

BitmapDrawable navigationBackground = new BitmapDrawable(BitmapFactory.decodeResource(
                getResources(), R.drawable.button_inner_shadow));
navigationBackground.setTileModeX(Shader.TileMode.REPEAT);
navigationTextViews[id].setBackgroundDrawable(navigationBackground);
2:使用xml平铺图像

navigationBackground = new BitmapDrawable(BitmapFactory.decodeResource(
                getResources(), R.drawable.navigation_background));
navigationTextViews[id].setBackgroundDrawable(navigationBackground);
导航背景

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

我做错了什么

我还使用了
setBackgroundResource
设置程序另一部分的背景颜色,并认为这是一个问题。我添加了
navigationTextViews[id].setBackgroundResource(0),它应该删除后台资源,而这与我使用的上述解决方案不起作用


编辑:navigationTextViews[]是一个文本视图数组

由于某些原因,第一个选项适用于不同的图像,因此我猜问题是我的第一个图像(具有一定透明度的渐变)太透明了。

日志猫,您遇到了什么错误?