1

I am trying to make an ImageView smaller as the user scrolls, using LayoutParams. The problem is, when the imageview size is decreased, it looks awful due to the default downsampling which occurs -

Original

Resized and jaggy image

Resized

Original Layout

Code

Downsampling

@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean b1) {

    int newCoverWidth = (int) (initialCoverWidth - (float) scrollY / 1.8);
    //ImageView which is resized
    ivBookCover.getLayoutParams().width = Math.max(newCoverWidth, initialCoverWidth / 2);
    rvBookPanel.setTranslationY(Math.max(-scrollY / 4, -initialToolBarHeight / 4));

    ivBookCover.requestLayout();
}

Setting of Bitmap

    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    ivBookCover.setImageBitmap(bmp);

What should i do to improve downscaling and get a smooth image

Shubham Kanodia
  • 6,036
  • 3
  • 32
  • 46

0 Answers0