Glide知識點總結

1.加載網絡圖片

使用Glide

xml頁面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="get"
        android:onClick="loadImage"/>
    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

 java代碼


public class TestIIActivity extends Activity{

    private ImageView imageView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test2);
        imageView = (ImageView) findViewById(R.id.image);
    }

    public void loadImage(View View){
        String url="https://www.baidu.com/img/bd_logo1.png?where=super";
        Glide.with(this)/*在哪個頁面顯示*/
             .load(url)/*加載的網絡圖片地址*/
             .placeholder(R.drawable.loading2)/*預顯示佔位圖*/
             .dontAnimate()/*不進行圖片的拉伸*/
             .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)/*強制讓圖片原大小顯示*/
             .into(imageView);/*在ImageView中顯示*/
    }

}

效果展示:(不會做動態圖,(lll¬ω¬))

                

 

 

2.Glide4.4使用方法

2.1 基礎使用

String url="https://www.baidu.com/img/bd_logo1.png?where=super";
            RequestOptions options=new RequestOptions()
                    .placeholder(R.drawable.loading2)
                    .diskCacheStrategy(DiskCacheStrategy.NONE);
            GlideUtil.load(itemView.getContext(),url,imageView,options);

public class GlideUtil {

    public static void load(Context context, String url, ImageView imageView, RequestOptions options) {
        Glide.with(context)
                .load(url)
                .apply(options)
                .into(imageView);
    }

}

2.2 

最近做的一個項目再次用到Glide,但知識簡單的使用已經不能滿足需要了,這裏新增一些內容吧:

thumbnail()     縮略圖

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章