url 中的 ImageView 未在真实设备中显示
ImageView from url not show in real device
imageview 在模拟器上显示,但在真实设备上不显示,我遵循 androidhive
中的教程
myjava.java
url_get_photo = "http://www.myurl.com/"
String key = getIntent().getStringExtra("key");
int loader = R.drawable.photo_blank;
ImageView image = (ImageView) findViewById(R.id.img_photo);
String image_url = (url_get_photo + key + ".jpg");
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(image_url, loader, image);
myactivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/img_photo"
android:layout_width="150dp"
android:layout_height="150dp" />
.......
我不知道为什么。出了什么问题?提前致谢。
请检查您的图片 URL 和互联网权限。
检查您的代码
int loader = R.drawable.loader;
// Imageview to show
ImageView image = (ImageView) findViewById(R.id.image);
// Image url
String image_url = "http://api.androidhive.info/images/sample.jpg";
// ImageLoader class instance
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
// whenever you want to load an image from url
// call DisplayImage function
// url - image url to load
// loader - loader image, will be displayed before getting image
// image - ImageView
imgLoader.DisplayImage(image_url, loader, image);
我建议你使用 Picasso、Glide、Fresco、ImageRequest(Volley) 等具有许多功能的库可以帮助你完成此任务。
Picasso.with(context).load("http://www.tecnologia.net/wp-content/uploads/2015/05/Los-mejores-trucos-para-Android.png").into(yourImageView);
Glide.with(context).load("http://www.tecnologia.net/wp-content/uploads/2015/05/Los-mejores-trucos-para-Android.png").into(yourImageView);
不要忘记在您的项目中导入库。
看这个linkhttp://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en
imageview 在模拟器上显示,但在真实设备上不显示,我遵循 androidhive
中的教程myjava.java
url_get_photo = "http://www.myurl.com/"
String key = getIntent().getStringExtra("key");
int loader = R.drawable.photo_blank;
ImageView image = (ImageView) findViewById(R.id.img_photo);
String image_url = (url_get_photo + key + ".jpg");
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
imgLoader.DisplayImage(image_url, loader, image);
myactivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/img_photo"
android:layout_width="150dp"
android:layout_height="150dp" />
.......
我不知道为什么。出了什么问题?提前致谢。
请检查您的图片 URL 和互联网权限。
检查您的代码
int loader = R.drawable.loader;
// Imageview to show
ImageView image = (ImageView) findViewById(R.id.image);
// Image url
String image_url = "http://api.androidhive.info/images/sample.jpg";
// ImageLoader class instance
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
// whenever you want to load an image from url
// call DisplayImage function
// url - image url to load
// loader - loader image, will be displayed before getting image
// image - ImageView
imgLoader.DisplayImage(image_url, loader, image);
我建议你使用 Picasso、Glide、Fresco、ImageRequest(Volley) 等具有许多功能的库可以帮助你完成此任务。
Picasso.with(context).load("http://www.tecnologia.net/wp-content/uploads/2015/05/Los-mejores-trucos-para-Android.png").into(yourImageView);
Glide.with(context).load("http://www.tecnologia.net/wp-content/uploads/2015/05/Los-mejores-trucos-para-Android.png").into(yourImageView);
不要忘记在您的项目中导入库。
看这个linkhttp://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en