【发布时间】: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