2011-06-13 62 views
0

我想在我创建的布局中沿x方向有平铺背景。我已经按照在线发现的一些很好的说明来正确拼贴,但源图像现在垂直伸展很好。我认为这与位图文件类型的性质有关。Android平铺背景图片:使用位图调整图片大小?

例图片:

enter image description here

第一图像是平铺之前的背景图像。第二张图片是在平铺之后。正如你所看到的,图像垂直伸展很好,并且由于调整大小,图像也显得有些模糊。

我试过把图像放在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> 

“@绘制/ 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平铺,是否有替代方案?或者有没有一些解决方法,我还没有检查?我已经更改了抗锯齿,抖动,滤镜等所有选项。没有任何东西可以改变。

感谢您的帮助!

编辑:这似乎是一个使用图形布局工具的错误。它在我的手机上看起来不错。

回答

0

这似乎是一个使用图形布局工具的错误。它在我的手机上看起来不错。

0

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

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

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

例如:如果我们有一个TextView“文本”,然后 text.setBackgroundDrawable(位)将设置该文本的背景 - 将
改为“位图”。

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

希望这有助于。