android–ViewPager在刷卡时太慢(使用Picasso)

android–ViewPager在刷卡时太慢(使用Picasso),第1张

概述我从我的画廊收到所有图片.(三星galaxys5的照片)我可以从Viewpager查看图像.但是当我开始Swiping时.它太慢了.几秒钟后,应用程序崩溃,没有logcat中的错误.publicclassPagingextendsPagerAdapter{privateArrayList<String>IMAGES=newArrayList<>();

我从我的画廊收到所有图片.(三星galaxy s5的照片)
我可以从VIEwpager查看图像.
但是当我开始SwiPing时.它太慢了.
几秒钟后,应用程序崩溃,没有logcat中的错误.

public class Paging extends PagerAdapter {        private ArrayList<String> IMAGES = new ArrayList<>();        private Context context;        private LayoutInflater layoutInflater;        public Paging(Context context) {            this.context = context;        }        @OverrIDe        public int getCount() {            return MainActivity.IMAGES.size();        }        @OverrIDe        public boolean isVIEwFromObject(VIEw vIEw, Object object) {            return (vIEw == (linearLayout) object);        }        @OverrIDe        public VIEw instantiateItem(VIEw container, int position) {            IMAGES = (ArrayList<String>) MainActivity.IMAGES.clone();            layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);            VIEw item_vIEw = layoutInflater.inflate(R.layout.imagepager_layout, (VIEwGroup) container, false);            ImageVIEw imageVIEw = (ImageVIEw) item_vIEw.findVIEwByID(R.ID.img);            Picasso.with(context)                    .load(IMAGES.get(position))                    .placeholder(R.drawable.plusbtn)                    .into(imageVIEw);        ((VIEwGroup) container).addVIEw(item_vIEw);            return item_vIEw;        }        @OverrIDe        public voID destroyItem(VIEwGroup container, int position, Object object) {            container.removeVIEw((linearLayout) object);        }    }

我的vIEwPager添加适配器.

 vIEwPager = (VIEwPager)findVIEwByID(R.ID.vIEw_pager); adap = new Paging(MainActivity.this); vIEwPager.setAdapter(adap);

我的XML ..

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:gravity="center_vertical"    androID:orIEntation="vertical">    <ImageVIEw        androID:ID="@+ID/img"        androID:layout_wIDth="wrap_content"        androID:layout_height="fill_parent"        androID:layout_gravity="center"        androID:gravity="center" /></linearLayout>

我的观点是寻呼机.

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:orIEntation="vertical"    >    <androID.support.v4.vIEw.VIEwPager        androID:ID="@+ID/vIEw_pager"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"></androID.support.v4.vIEw.VIEwPager></linearLayout>

解决方法:

这很可能是因为加载的图像像素数据太多而不是必要的(以适应您的视图大小).如果您的图像尺寸很大,默认情况下Picasso会将图像的完整大小加载到内存中,从而导致帧速率慢和OOM异常.

快速解决方法是使用Picasso.with().load().resize(wIDth,height).它将使Picasso能够将缩减采样版本的图像加载到内存中.在UI端,您可以为ImageVIEw使用fitCenter比例类型.

但是,为了更好地理解这个概念,我建议在这里阅读更多有关此主题的Google开发者指南:Loading Large Bitmaps Efficiently

总结

以上是内存溢出为你收集整理的android – ViewPager在刷卡时太慢(使用Picasso)全部内容,希望文章能够帮你解决android – ViewPager在刷卡时太慢(使用Picasso)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1118204.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存