037 Android Glide image is loaded using the open-source framework

1.Glide brief

  Glide is a developed by Bump Technologies of image loading frame , so that we can be extremely simple way to load and display pictures on the Android platform. Glide is a fast and efficient Android image loading library, focus on a smooth scrolling. Glide provides a user-friendly API, high performance, scalable picture decoding pipeline ( decode pipeline), and automatic resource pooling.

  Glide support pull, decode and display video snapshots, images, and animated GIF. The Api Glide is so flexible, developers can even insert and replace any of your favorite network stack. By default, Glide uses a custom-based HttpUrlConnectionstack, but it also provides a quick integration with Google Volley Square OkHttp tools and libraries.

2.Glide use environment configuration

(1) add dependencies

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

(2) add a network permission

<uses-permission android:name="android.permission.INTERNET" />

3.Glide simple use case

(1) xml page layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/bt_pic_loader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="加载图片" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp" />

    <ImageView
        android:id="@+id/iv_pic"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

(2) java background

package com.example.administrator.test67glide;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

public class MainActivity extends AppCompatActivity {

    Button bt_pic_loader;
    ImageView imageView;
    ImageView iv_pic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        the setContentView (R.layout.activity_main); 

        bt_pic_loader = the findViewById (R.id.bt_pic_loader); 
        the imageView = the findViewById (R.id.imageView); 
        iv_pic = the findViewById (R.id.iv_pic); 
        iv_pic.setImageResource (R.mipmap. news_pic_default); 
        iv_pic.setScaleType (ImageView.ScaleType.FIT_XY); // set of image scaling, Brand high filling parent control 

        bt_pic_loader.setOnClickListener ( new new View.OnClickListener () { 
            @Override 
            public  void the onClick (View V) {
                 // Glide load the network using the picture 
                String url = " http://118.25.152.62:8080/zhbj/10007/1452327318UU91.jpg " ;
                Glide.with(getApplicationContext()).load(url).into(imageView);

            }
        });

    }
}

(3) Effects of FIG.

 References: https: //www.jianshu.com/p/4f457a124d67

Guess you like

Origin www.cnblogs.com/luckyplj/p/10941936.html