가능한 중복 :
Image not showing on image view어떻게 안드로이드에 이미지를 표시하는
서버 하시기 바랍니다 할 수있는 사람이 공유에서 그것을 다운로드하는 동안 안드로이드의 이미지를 표시하는 방법 나에 관한이 코드
가능한 중복 :
Image not showing on image view어떻게 안드로이드에 이미지를 표시하는
서버 하시기 바랍니다 할 수있는 사람이 공유에서 그것을 다운로드하는 동안 안드로이드의 이미지를 표시하는 방법 나에 관한이 코드
URL에서 이미지를 가져 와서 imageview에 표시하려면 아래 코드를 사용하십시오. AsycTask를 사용하여 다운로드하는 동안
public class image extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bitmap bitmap = DownloadImage("http://www.gophoto.it/view.php?i=http://1.bp.blogspot.com/-2LTvCCufBKc/T3L3KgcTj2I/AAAAAAAABbQ/Ki60e1LU9sE/s1600/Sachin%2BTendulkar.png");
RelativeLayout mRlayout1 = (RelativeLayout) findViewById(R.id.mRlayout1);
Drawable d=new BitmapDrawable(bitmap);
mRlayoutLogin.setBackgroundDrawable(d);
}
private InputStream OpenHttpConnection(String urlString) throws IOException {
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
} catch (Exception ex) {
throw new IOException("Error connecting");
}
return in;
}
private Bitmap DownloadImage(String URL) {
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
}
}
Drawable drawable = LoadImage(ImageURL);
PhotoImageView.setImageDrawable(drawable);
//PhotoImageView is the ImageView in which you want to load your image from server
public Drawable LoadImage(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}
catch (Exception e)
{
System.out.println("Exc=" + e);
return null;
}
}
보통 당신은 ProgressBar의 회전을 보여
public class Downloader extends AsyncTask<String,Integer,Bitmap> {
@Override
protected void onPreExecute() {
// show spinning progress bar
}
@Override
protected Bitmap doInBackground(String... arg0) {
// download the image
return null;
}
@Override
protected void onPostExecute(Bitmap downloadedImage) {
// hide spinning progress bar
// show downloaded image
}
}
가 당신을 도울 수있는이보십시오.
class DownloadImage extends AsyncTask<Void, Void, Void> {
private ProgressDialog bar;
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
bar.dismiss();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
bar = new ProgressDialog(context);
bar.setIndeterminate(true);
bar.setTitle(context.getString(R.string.app_name));
bar.setMessage(context.getString(R.string.please_wait));
bar.show();
}
@Override
protected Void doInBackground(Void... arg0) {
downloadImage();
return null;
}
void downloadImage() {
//Put the logic for download image from url
}
}
또는 시도 무슨 here.
확인하시기 바랍니다? –
자신을 시험해보십시오! .. –
@ user1972094 URL에서 이미지를 다운로드하거나 이미지를 다운로드 할 때까지 다운로드가 진행되고 있음을 나타내는 기본 이미지를 표시하려고합니다. –