zoukankan      html  css  js  c++  java
  • 安卓学习07

    
    

    今日学习了Glide和SwipeRefreshLayout。

    1、Glide

    • 官方简介:Glide是一个快速高效的Android图片加载库,注重于平滑的滚动。Glide提供了易用的API,高性能、可扩展的图片解码管道(decode pipeline),以及自动的资源池技术。

    • Glide的使用也是比较简单,最基础的使用代码:

      Glide.with(fragment)
          .load(url)
          .into(imageView);
    • 依赖:

      implementation 'com.github.bumptech.glide:glide:4.11.0'
      annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

    实际操作:

    Glide.with(this)
                    .load(url)
                    .placeholder(R.drawable.ic_launcher_background)
                    .listener(new RequestListener<Drawable>() {
                        @Override
                        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                            if (swipeRefreshLayout.isRefreshing()){
                                swipeRefreshLayout.setRefreshing(false);
                            }
                            return false;
                        }
    ​
                        @Override
                        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                            if (swipeRefreshLayout.isRefreshing()){
                                swipeRefreshLayout.setRefreshing(false);
                            }
                            return false;
                        }
                    })
                    .into(imageView);

    2、SwipeRefreshLayout

    • 依赖:

      implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    • 需要在布局中将顶层容器换为swiperefreshlayout,并为其设置id以供使用。

    • 实际使用:

      swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
      swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                  @Override
                  public void onRefresh() {
                      imageLoad();
                  }
              });
      • imageLoad()为glide封装的图片加载函数。

  • 相关阅读:
    Windows Server 2012 R2 或 2016 无法安装 .Net 3.5.1
    织梦DeDeCms会员登录或退出跳转到首页的修改方法
    use ngCordova in ionic
    Angular2 Todo App
    use traceur in ES6
    Angular2 Use styles in Component
    Angular2 use ng-xx (ng-if)
    Angular2 Router
    Angular2 Http
    1 TypeScript SetUp for Webstorm
  • 原文地址:https://www.cnblogs.com/wuren-best/p/12288792.html
Copyright © 2011-2022 走看看