【问题标题】:Android Bitmap Drawable adjustable widthAndroid Bitmap Drawable 可调宽度
【发布时间】:2015-06-29 14:37:56
【问题描述】:

我有一个 android 活动,其中有一个覆盖背景图像的图像。 2 个图像必须对齐(仅高度),因此不得缩放背景图像的高度。 但是,在宽显示器上,我需要拉伸此背景的宽度以适合屏幕。 目前我已经这样设置了Activity背景。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layRoot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/meditation_bg">

meditation_bg 是一个可绘制的资源。代码是

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/morn_blur_bg"
    android:gravity="top|center"
    android:scaleType="centerCrop"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />

需要位图可绘制资源以防止操作系统为我缩放图像。

如何在不影响图片高度的情况下控制宽度。

干杯,

【问题讨论】:

  • 我真的不明白你真正需要实现什么......
  • 嗨,我需要在不影响高度的情况下拉伸背景图像的宽度。高度必须保持不变。

标签: android bitmap


【解决方案1】:

我强烈建议您查看Picasso,它们提供图像缓存,调整更容易。

【讨论】:

  • 谢谢,我设法使用 resize() 函数调整宽度,我将宽度设置为 800 以匹配屏幕,但它在两侧留下了一个间隙,它没有完全填满,任何想法为什么?
  • @Rival 您可能必须使用 .centerCrop,例如 Picasso.with(parent.getContext()).load(urlForImageInServer).resize(700, 450).centerCrop().into(ImageView );
猜你喜欢
  • 2011-02-07
  • 1970-01-01
  • 2012-04-26
  • 1970-01-01
  • 1970-01-01
  • 2011-01-25
  • 1970-01-01
  • 1970-01-01
  • 2012-02-11
相关资源
最近更新 更多