티스토리 뷰
ImageView Picasso, Glide Library 사용.
Picasso : http://square.github.io/picasso/
Glide : https://github.com/bumptech/glide
Manifast.xml
<uses-permission android:name="android.permission.INTERNET" /> |
gradle
compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.squareup.picasso:picasso:2.5.2' |
Mainactivity.java( Picasso )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | public class MainActivity extends AppCompatActivity { ImageView imageView; Button button; ProgressBar bar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bar = (ProgressBar) findViewById(R.id.progressBar); imageView = (ImageView) findViewById(R.id.imageView); button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url ="http://( sampleImage주소 )"; bar.setVisibility(View.VISIBLE); Picasso.with(MainActivity.this).load(url).into(imageView, new Callback() { @Override public void onSuccess() { bar.setVisibility(View.GONE); } @Override public void onError() { } }); } }); } } | cs |
Mainactivity.java( Glide )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | public class MainActivity extends AppCompatActivity { ImageView imageView; Button button; ProgressBar bar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bar = (ProgressBar) findViewById(R.id.progressBar); imageView = (ImageView) findViewById(R.id.imageView); button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url ="http://( sampleImage주소 )"; bar.setVisibility(View.VISIBLE); Glide.with(MainActivity.this).load(url).listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { bar.setVisibility(View.GONE); return false; } @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { bar.setVisibility(View.GONE); return false; } }) .into(imageView); } }); } } | cs |
'ANDROID > android' 카테고리의 다른 글
android FireBase 사용하기 (0) | 2016.10.28 |
---|---|
android Retrofit with OKhttp (0) | 2016.10.26 |
android HTTP Cookie 사용. (0) | 2016.10.25 |
android HTTP URL Connection (0) | 2016.10.25 |
android HTTP URL Connection/Open API 사용해 보자. (0) | 2016.10.21 |
Comments