Resize image to full width and variable height with Picasso

前端 未结 12 1590
野趣味
野趣味 2020-11-29 17:10

I have a listView with an adapter that contains ImageView of variable size (width and height). I need resize the pictures load with Picasso to the max width of

12条回答
  •  误落风尘
    2020-11-29 18:06

    extend ImageView then override onMeasure method like the following.

    @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
            Drawable d = getDrawable();
    
            if(d!=null && fittingType == FittingTypeEnum.FIT_TO_WIDTH){
                int width = MeasureSpec.getSize(widthMeasureSpec);
                int height = (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() / (float) d.getIntrinsicWidth());
                setMeasuredDimension(width, height);
            }else{
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }
    

提交回复
热议问题