【问题标题】:Android programmatically tile image as backgroundAndroid以编程方式将图像平铺为背景
【发布时间】:2012-06-27 06:47:14
【问题描述】:

我有一张想要水平平铺的图像,我需要以编程方式完成。两种方法都试过了,都不行。

button_inner_shadow 是图像 navigation_background 是假设平铺上图的 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[] 是一个 TextViews 数组

【问题讨论】:

  • 你得到了什么错误,发布 logcat?

标签: android image background


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多