扫码关注官方订阅号
在iOS中可以设置一个控件的宽高比,比如说一个ImageView的宽设置为屏幕的宽度,高等于宽度,即这个ImageView是正方形,而且适配所有机型。在Android的xml怎么设置呢?
认证高级PHP讲师
重写一个view extends Imageview,然后
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = Math.round(width*ratio); setMeasuredDimension(width,height); }
这个ratio设置成1
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
重写一个view extends Imageview,然后
这个ratio设置成1