【Android】ImageView宽固定,高自适应/高固定,宽自适应(正方形图片)

网友投稿 758 2022-11-24

【Android】ImageView宽固定,高自适应/高固定,宽自适应(正方形图片)

【Android】ImageView宽固定,高自适应/高固定,宽自适应(正方形图片)

ImageView宽固定,高自适应/高固定,宽自适应

解决方法

​​宽固定,高自适应​​

​​高固定,宽自适应​​

也可以自己写个正方形的ImageView

class SquareImageView : AppCompatImageView { constructor(context: Context) : this(context, null) constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {} override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val width = MeasureSpec.getSize(widthMeasureSpec) val mheightMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY) super.onMeasure(widthMeasureSpec, mheightMeasureSpec) }}

​​怎么用? 结合dataBinding,glide,可美观了​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【Android】include子布局获取父布局的DataBinding
下一篇:AWVS14批量漏洞扫描Docker篇
相关文章

 发表评论

暂时没有评论,来抢沙发吧~