首页 文章

Android平铺背景图片:使用位图调整图像大小?

提问于
浏览
0

我想在x方向上创建一个布局的平铺背景 . 我已经按照在线发现的一些好的指示正确地进行了平铺,但是源图像现在已经垂直拉伸了很多 . 我认为这与位图文件类型的性质有关 .

示例图片:

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>

“@ 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平铺有替代方法吗?或者是否有一些我还没有检查过的解决方法?我已经改变了抗锯齿,抖动,过滤器等的所有选项 . 似乎什么都没有改变 .

谢谢您的帮助!

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

3 回答

  • 0

    请查看以下链接:Link1

    Link2

    希望这些能帮到你!!!

  • 0

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

  • 0

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

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

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

    例如:如果我们有TextView "text"那么text.setBackgroundDrawable(位图)将设置此文本视图的背景
    到"bitmap" .

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

    希望这可以帮助 .

相关问题