Imageview automatically adjusts Images that are loaded into it

142 views Asked by At

I am using glide to load images into an imageview that uses viewpager2 to slide through images.When I load an image to the imageview it first fills the width of the screen then it increases in width again like it's imitating a zooming behaviour. My glide implementation:

glide.asBitmap().load(images.get(position)).apply(options).listener(new RequestListener<Bitmap>() {
            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                ((Activity) context).startPostponedEnterTransition();
                return false;
            }

            @Override
            public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                ((Activity) context).startPostponedEnterTransition();
                return false;
            }
        }).into(holder.photoView);

The request options:

RequestOptions options = new RequestOptions()
                .placeholder(R.color.black)
                .error(R.color.black)
                 .dontTransform()
            
                .skipMemoryCache(true)
                //. encodeFormat(Bitmap.CompressFormat.PNG)
                //.priority(Priority.IMMEDIATE)
                .format(DecodeFormat.PREFER_ARGB_8888)
                .diskCacheStrategy(DiskCacheStrategy.NONE);



ViewPager Xml:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/myRel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    tools:context=".ShowImage">



    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"
        android:layout_centerInParent="true"

        />
    <include

        android:id="@+id/show_Image_toolbar"
        layout="@layout/image_custom_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:transitionName="transitionToolbar"
        />


</RelativeLayout>

Viewpager2 inflater layout for the Imageview:

 <androidx.appcompat.widget.AppCompatImageView
        xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/photoView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:layout_weight="1"

    />
1

There are 1 answers

0
Kenart On BEST ANSWER

Apparently this happened because I was doing too much processing/work on the UI thread so the loading and transition of the images were slowed down causing the ImageView to lag.