SoFunction
Updated on 2025-03-01

Android picture loading cache frame Glide

Glide open source framework is Google's recommended image loading and ease framework, and its open source address on Github is:/bumptech/glide
Of course, a framework recommended by Google must be Volley.
Currently, the mainstream development tool for Android is AndroidStudio. How to use Glide in AndroidStudio,/bumptech/glideThere is a detailed introduction on it.
Because I just changed my new job and the company still has Eclipse, so I used the Eclipse development tool I still use for the time being when I learned Glide.
step:
Add package to the project, the jar package can be downloaded online.
Writing code

public class MainActivity extends Activity {
  private ImageView glide_iv;
  private ListView glide_lv;
  private static final String URL ="Write a picture url here";
  private List<String> urls = new ArrayList<String>();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    setContentView(.activity_main);
    initDatas();
    glide_iv = (ImageView) findViewById(.glide_iv);
    // Loading network images into ImageView through the following code is very convenient    //Glide's with method not only accepts Context, but also accepts Activity and Fragment, etc. Context will automatically obtain from them, which is very convenient to use    (this).load(URL).into(glide_iv);
    glide_lv = (ListView) findViewById(.glide_lv);
    glide_lv.setAdapter(new BaseAdapter() {

      @Override
      public View getView(int arg0, View contentView, ViewGroup arg2) {
        ViewHolder holder=null;
        if (contentView == null) {
          holder=new ViewHolder();
          contentView= (
              ).inflate(.my_image_view,
              null);
           = (.item_iv);
          (holder);
        } else {
          holder=(ViewHolder) ();
        }

        String url = (arg0);
        //Load the list image in ListView        ().load(url).centerCrop()
            .placeholder(.ic_launcher).crossFade()
            .into();

        return contentView;
      }

      @Override
      public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
      }

      @Override
      public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return (arg0);
      }

      @Override
      public int getCount() {
        // TODO Auto-generated method stub
        return ();
      }
      class ViewHolder{
        ImageView itemIv;
      }
    });
  }

  /**
    * Add data
    */
  private void initDatas() {
    for (int i = 0; i < 5; i++) {
      (URL);
    }
  }
}

Layout file:

<RelativeLayout xmlns:andro
  xmlns:tools="/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:padding="20dp" >

  <ImageView
    android:
    android:layout_width="80dp"
    android:layout_height="80dp" />

  <ListView
    android:
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_below="@id/glide_iv">
  </ListView>

</RelativeLayout>

Finally, remember to add network permissions:

<uses-permission android:name="" >

The above is all about this article, I hope it will be helpful to everyone's learning.