如何解决Imageview自动调整加载到其中的图像
我正在使用滑行将图像加载到使用viewpager2在图像视图中滑动的图像视图中。当我将图像加载到图像视图中时,它首先填充了屏幕的宽度,然后又增加了宽度,就像在模仿缩放行为一样。 我的滑行实现:
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,DataSource dataSource,boolean isFirstResource) {
((Activity) context).startPostponedEnterTransition();
return false;
}
}).into(holder.photoView);
请求选项:
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>
Imageview的Viewpager2充气机布局:
<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"
/>
解决方法
显然是因为我在UI线程上进行了过多的处理/工作,所以图像的加载和转换速度变慢,导致ImageView滞后。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。