最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android組件Glide實現(xiàn)圖片平滑滾動效果

 更新時間:2016年07月11日 11:06:50   投稿:lijiao  
這篇文章主要介紹了Android組件Glide實現(xiàn)圖片平滑滾動效果的相關(guān)資料,具有一定的參考價值,需要的朋友可以參考下

Glide是一款基于Android的圖片加載和圖片緩存組件,它可以最大性能地在Android設(shè)備上讀取、解碼、顯示圖片和視頻。Glide可以將遠程的圖片、視頻、動畫圖片等緩存在設(shè)備本地,便于提高用戶瀏覽圖片的流暢體驗。

Glide最核心的功能就是提高滾動圖片列表的性能,并且Glide還能滿足對遠程圖片的讀取、改變尺寸以及展示的性能要求。

Glide使用方法

最簡單的示例代碼如下:

// For a simple view:
@Override
public void onCreate(Bundle savedInstanceState) {
  ...

  ImageView imageView = (ImageView) findViewById(R.id.my_image_view);

  Glide.with(this).load("http://goo.gl/h8qOq7").into(imageView);
}

// For a list:
@Override
public View getView(int position, View recycled, ViewGroup container) {
  final ImageView myImageView;
  if (recycled == null) {
    myImageView = (ImageView) inflater.inflate(R.layout.my_image_view,
        container, false);
  } else {
    myImageView = (ImageView) recycled;
  }

  String url = myUrls.get(position);

  Glide.with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .crossFade()
    .into(myImageView);

  return myImageView;
}

在Glide上應用Volley通信框架

Volley是Glide的可選項,可以支持http/https來讀取圖片。

用Gradle:

dependencies {
  compile 'com.github.bumptech.glide:volley-integration:1.0.+'
  compile 'com.mcxiaoke.volley:library:1.0.+'
}

或者用Maven:

<dependency>
  <groupId>com.github.bumptech.glide</groupId>
  <artifactId>volley-integration</artifactId>
  <version>1.0.1</version>
  <type>jar</type>
</dependency>
<dependency>
  <groupId>com.mcxiaoke.volley</groupId>
  <artifactId>library</artifactId>
  <version>1.0.5</version>
  <type>aar</type>
</dependency>

然后在Activity或者Application中注冊 Volley的加載項即可:

public void onCreate() {
 Glide.get(this).register(GlideUrl.class, InputStream.class,
    new VolleyUrlLoader.Factory(yourRequestQueue));
 ...
}

這樣所有的請求就會通過Volley了。

在Glide中應用OKHttp通信框架

除了Volley,Glide中還可以使用OkHttp通信框架,OkHttp同樣支持http/https來讀取圖片。

用Gradle:

dependencies {
  compile 'com.github.bumptech.glide:okhttp-integration:1.0.+'
  compile 'com.squareup.okhttp:okhttp:2.0.+'
}

或者用Maven:

<dependency>
  <groupId>com.github.bumptech.glide</groupId>
  <artifactId>okhttp-integration</artifactId>
  <version>1.0.1</version>
  <type>jar</type>
</dependency>
<dependency>
  <groupId>com.squareup.okhttp</groupId>
  <artifactId>okhttp</artifactId>
  <version>2.0.0</version>
  <type>jar</type>
</dependency>

然后在Activity或者Application中注冊 OkHttp的加載項即可:

public void onCreate() {
 Glide.get(this).register(GlideUrl.class, InputStream.class,
    new OkHttpUrlLoader.Factory(yourOkHttpClient));
 ...
}

總結(jié)

如果你的Android應用中涉及到遠程圖片的處理,那么Glide組件可以幫助你在圖片視頻方面優(yōu)化應用程序。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

安达市| 筠连县| 定结县| 临夏县| 伊吾县| 卫辉市| 新丰县| 龙井市| 巴林右旗| 榆中县| 阳朔县| 防城港市| 钟山县| 姜堰市| 汶川县| 凌海市| 崇州市| 图木舒克市| 驻马店市| 博湖县| 崇礼县| 桐城市| 宜城市| 广南县| 白沙| 离岛区| 海南省| 梧州市| 大同市| 微博| 昌江| 青神县| 抚州市| 黎川县| 清镇市| 石景山区| 临泉县| 盐山县| 醴陵市| 长子县| 阳东县|