如何使android imageview变成正方形? [英] How do I make android imageview square?

查看:227
本文介绍了如何使android imageview变成正方形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Android项目中使用 ImageView .

I'm using an ImageView in an Android project.

宽度: match_parent 高度: wrap_content

然后将其缩放为 fill_XY ,但是图像还没有正方形...我该怎么办?

then I scale it to fill_XY, but the image is not square yet... what can I do?

推荐答案

正方形图像的最佳方法是将 ConstraintLayout constraintDimensionRatio 结合使用,而无需给出固定的高度/宽度./p>

The best way for square image is use ConstraintLayout with constraintDimensionRatio Without give fix height/width.

  <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ImageView
        android:id="@+id/image"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="H,1:1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

这篇关于如何使android imageview变成正方形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆