2010/09/05 18:59 http://loadtodream.blog.me/30093256249 |
In android we can show image from URL (web).
Here we are going to see about how to load the image from web in simple way.
Example for Android Load Image From Web :-
Add the below code to AndroidManifest.xml for Internet Permission.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Edit your main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:id="@+id/ImageView01"
android:layout_height="wrap_content" android:layout_width="wrap_content"/>
</LinearLayout>
Edit your java file
import java.io.InputStream;
import java.net.URL;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;public class ImageFromUrlExample extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);ImageView imgView =(ImageView)findViewById(R.id.ImageView01);
Drawable drawable = LoadImageFromWebOperations("http://www.androidpeople.com/wp-content/uploads/2010/03/android.png");
imgView.setImageDrawable(drawable);}
private Drawable LoadImageFromWebOperations(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;
}
}
}
'Android > Tip&Tech' 카테고리의 다른 글
[펌]progress dialog 참고예제 (0) | 2010.12.10 |
---|---|
[펌]listview에 progress 적용참고 팁 (0) | 2010.12.10 |
[펌][안드로이드] TextView의 색상, 효과를 부분적으로 적용하는 방법 (0) | 2010.12.10 |
아이콘 추천 사이트 (0) | 2010.12.09 |
Tservice agent파일 (0) | 2010.12.09 |