首页 > android中如何设置ImageView的宽高比?

android中如何设置ImageView的宽高比?

在iOS中可以设置一个控件的宽高比,比如说一个ImageView的宽设置为屏幕的宽度,高等于宽度,即这个ImageView是正方形,而且适配所有机型。
在Android的xml怎么设置呢?


基于谷歌官方的库 android-percent-support 的增强版百分比布局库
http://blog.csdn.net/lmj623565791/article/details/46767825


重写一个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

【热门文章】
【热门文章】