【问题标题】:ImageView Scaling: fix height variable width with maxWidthImageView 缩放:使用 maxWidth 修复高度可变宽度
【发布时间】:2014-11-08 12:09:13
【问题描述】:

我将展示一些图片,但我的限制是作为标题。我想让所有图像具有相同的高度,但根据它们的宽度,它们必须具有不同的宽度。我只是不想在缩放时丢失图像的任何部分。这是我的代码:

    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/ImageView_IssueFirstLookActivity_magas"
        android:layout_width="wrap_content"
        android:layout_height="170dp"
        android:layout_marginLeft="32dip"
        android:layout_weight="2"
        android:maxWidth="40dp"
        android:adjustViewBounds="true"
        android:scaleType="fitStart" />

我尽我所能使用android:scaleType 的不同值,但一无所获。 这是我想要的一个数字,但是当我使用这些属性时,它不会像我想要的那样缩放它,例如有时它不会完全显示图像宽度并且它会严重裁剪它。例如,另一个尝试是android:scaleType="fitStart",这会导致我的图像宽度很好,但高度不再合适。有什么想法吗?

【问题讨论】:

    标签: android android-layout android-imageview


    【解决方案1】:

    andriod ImageView 属性不支持你说的在布局xml中静态选择宽度、高度和saleType组合的要求。

    相反,您可以在 java 代码中通过实际查找给定固定高度的图像宽度并以编程方式将它们设置为 dp 中的每个视图(确保执行像素到 dp 计算以实现正确的输出,可销售跨设备)

    【讨论】:

      【解决方案2】:

      如果你不介意额外的依赖,你可以使用Picasso

      Picasso.get()
        .load(R.drawable.my_image_resource)
        .placeholder(R.drawable.ic_image_placeholder)
        .error(R.drawable.ic_broken_image)
        .resize(0, (int) imagefixedHeight)
        // optional:
        // .centerInside()
        .into(myImageView);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-03
        • 1970-01-01
        • 2016-04-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多