1. 程式人生 > >簡單網絡圖片加載

簡單網絡圖片加載

image 控件 放置 網絡 parent int oncreate ros ace

1、依賴裏面加入
compile ‘com.github.bumptech.glide:glide:3.6.1‘
2、布局裏面放置一個ImageView控件
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

3、代碼裏面
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_img_test);
ImageView img = (ImageView) findViewById(R.id.img);//layout中放一個ImageView控件,id是@+id/img
String url = "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3917297328,2353437284&fm=27&gp=0.jpg";
Glide.with(this).load(url).placeholder(R.drawable.myimg).crossFade().into(img);
}

簡單網絡圖片加載