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

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

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

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

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

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上應(yīng)用Volley通信框架

Volley是Glide的可選項(xiàng),可以支持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的加載項(xiàng)即可:

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

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

在Glide中應(yīng)用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的加載項(xiàng)即可:

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

總結(jié)

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

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

相關(guān)文章

最新評論

秦安县| 乡宁县| 健康| 星座| 司法| 罗田县| 绩溪县| 阿克陶县| 南召县| 宁国市| 阿拉善左旗| 宣武区| 休宁县| 马尔康县| 青岛市| 嘉鱼县| 于都县| 全州县| 盐源县| 观塘区| 中阳县| 黎平县| 太谷县| 右玉县| 清水河县| 凤山县| 长子县| 离岛区| 鱼台县| 周宁县| 柏乡县| 长白| 郁南县| 抚州市| 柳河县| 水富县| 永定县| 安多县| 利辛县| 华坪县| 尖扎县|