1

我想在我创建的布局中在 x 方向上有一个平铺背景。我已经按照网上找到的一些很好的说明正确平铺,但是源图像现在垂直拉伸了很多。我认为这与位图文件类型的性质有关。

示例图片:

在此处输入图像描述

第一个图像是平铺前的背景图像。第二张图片是平铺后的。如您所见,图像被垂直拉伸了一点,并且由于调整大小而显得有点模糊。

我尝试将图像放在 drawable-hdpi 和 drawable 文件夹中。我尝试将 XML 文件放在两个文件夹中。这些似乎都不重要。

这是生成这两个图像的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:background="@drawable/bg" />
<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:background="@drawable/bg_repeat" />
</LinearLayout>

“@drawable/bg”是实际图像本身,bg.png。“@drawable/bg_repeat”是以下位图 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/cdetail_bg_unclaimed_details"
android:antialias="false"
android:dither="false"
android:filter="false"
android:gravity="center|center_vertical"
android:tileMode="repeat" />

对于 x-repeat 平铺,是否有替代方法?还是有一些我还没有检查过的解决方法?我已经更改了抗锯齿、抖动、过滤器等的所有选项。似乎没有任何改变。

谢谢您的帮助!

编辑:这似乎是使用图形布局工具的错误。在我的手机上看起来还可以。

4

2 回答 2

0

这似乎是使用图形布局工具的错误。在我的手机上看起来还可以。

于 2011-06-15T14:17:36.037 回答
0

您不能使用 xml 在一个方向上重复位图背景,但 Java 代码肯定可以做到这一点。

BitmapDrawable bitmap = (BitmapDrawable) getResources().getDrawable(R.drawable.image);
 bitmap.setTileModeX(TileMode.REPEAT);

所以现在如果你把这个“位图”设置为任何视图的背景

例如:如果我们有一个 TextView "text" 那么 text.setBackgroundDrawable(bitmap) 将把这个 text-view 的背景设置
为 "bitmap"。

它会在 x 方向重复,但会在 y 方向保持高度

希望这可以帮助。

于 2013-06-26T11:36:16.043 回答