【问题标题】:Resize ImageView background accordingly to Image size根据图像大小调整 ImageView 背景大小
【发布时间】:2014-09-14 08:30:41
【问题描述】:

我正在尝试根据图像大小调整图像背景的大小

我有一个简单的 ImageView

  <ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:background="@drawable/white_bg"
    android:scaleType="fitCenter"
    android:padding="3dp"
    android:layout_height="wrap_content" />

white_bg 是一个 xml 可绘制对象

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="@android:color/white" />
    <corners android:radius="5dp" />
</shape>

问题是图像和背景之间有很大的空白。 似乎唯一能解决问题的方法是将 `ScaleType' 属性设置为 FitXY,但它会拉伸小图像并且它们会变得丑陋。

我还尝试使用 `wrap_content' 宽度和高度属性将 LinearLayout 父级添加到 ImageView,但某些图像仍然存在较大的空白。

【问题讨论】:

  • 我真的不明白你在找什么,你希望你的图片全屏,但你又不希望它们在较小尺寸时拉伸?所以你想要什么? (如果您将“当前结果”中的图片显示为“期望结果”,这将有所帮助
  • 我不介意图片是否全屏,我唯一想要的是背景调整为图片大小,第二张图片是想要的结果
  • 尝试将 'android:shape="rectangle"' 属性添加到 标记。

标签: android android-imageview


【解决方案1】:

试试这个

ImageView.setAdjustViewBounds(true);

不确定,但对你有帮助

【讨论】:

    猜你喜欢
    • 2019-10-16
    • 2015-05-05
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多