我使用a ListView来显示与这些图像相关的一些图像和标题.我从互联网上获取图像.有没有办法延迟加载图像,以便文本显示时,UI不会被锁定,图像会在下载时显示?
图像总数不固定.
我在res/drawable-mdpi目录中有一个条目列表和一些位图文件.我正在尝试通过生成路径字符串并使用位图工厂来加载与从列表中选择的字符串值对应的图像.问题是我不认为我的路径是正确的,因为位图始终为空,即使对于默认图像也是如此.
String name = entries.get(position);
String img = "res/drawable/logo_" + name.toLowerCase() + ".png"; // create the file name
icon.setScaleType(ImageView.ScaleType.CENTER_CROP);
// check to see if the file exists
File file = new File(img);
if (file.exists()){
bm = BitmapFactory.decodeFile(img);
}
else{// use the default icon
bm = BitmapFactory.decodeFile("logo_default.png");
}
// set the image and text
icon.setImageBitmap(bm);
Run Code Online (Sandbox Code Playgroud)
res目录是否会被复制到设备上?我应该使用的正确路径是什么,或者我应该以不同的方式进行此操作?
谢谢
我想使用Url在ImageView中设置Image,例如我有这个url
但是没有设置url的选项
我正在尝试在我正在构建的Android应用程序中发出一个http POST请求,但无论我使用什么URL请求,Eclipse都会引发格式错误的URL异常.我已经尝试了一个Android教程中的一行代码:
URL url = new URL("https://wikipedia.org");
Run Code Online (Sandbox Code Playgroud)
甚至那会触发错误.是否有理由为我尝试创建的任何URL不断引发此错误?
我关注Facebook SDK 3.0 for Android的问题.我想在不使用他们的ProfilePictureView小部件的情况下获取我的(和我的朋友)个人资料图片,所以如果我使用Graph Explorer,我会看到Json响应是:
{
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/372127_1377011138_1538716206_q.jpg",
"is_silhouette": false
}
}
Run Code Online (Sandbox Code Playgroud)
我需要"url"路径下载并显示图片,但使用以下代码:
Request.executeGraphPathRequestAsync(Session.getActiveSession(),
"me/picture",
new Request.Callback() {
@Override
public void onCompleted(Response response) {
GraphObject go = response.getGraphObject();
Log.i("APP_NAME", go.toString());
}
});
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
GraphObject{graphObjectClass=GraphObject,
state={"FACEBOOK_NON_JSON_RESULT":"????\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001\u0000\u0001\u0000\u0000??\u0000"}}
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?谢谢
Cromir
我在设置网址图像到图像视图时遇到问题.我试过以下方法
方法1:
Bitmap bimage= getBitmapFromURL(bannerpath);
image.setImageBitmap(bimage);
public static Bitmap getBitmapFromURL(String src) {
try {
Log.e("src",src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
Log.e("Bitmap","returned");
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
Log.e("Exception",e.getMessage());
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
方法2:
Drawable drawable = LoadImageFromWebOperations(bannerpath);
image.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 …Run Code Online (Sandbox Code Playgroud) 我想将一个淡入动画应用到ImageView,以创建在下载完成时从网址加载的图像淡入的效果.
我知道如何将图像从URL下载到ImageView,就像在这个答案中一样,我知道如何将淡入动画应用到像这里的imageView .
这种尝试
Drawable d = ImageUtils.fetchDrawable("the url");
imageView.setImageDrawable(d);
imageView.startAnimation(fadeInAnimation);
Run Code Online (Sandbox Code Playgroud)
导致眨眼效果(见,看不见,淡入看).反转最后两行的顺序也会导致闪烁.
我用Google搜索并搜索了一个回调/监听器形式的解决方案 - 类似这样:
imageView.setOnLoadCompleteListener...
Run Code Online (Sandbox Code Playgroud)
在ImageView中注册加载完成事件,但我没有在这些行中找到任何内容.
对于如何实现此效果的解决方案的任何指示,我将不胜感激.
我是一个新手程序员,我正在制作一个Android程序,在给定的URL上显示ImageView上的图像.我的问题是你如何在AsyncTask上使用它?
这些代码适用于最小的SDK 2.2,但我切换到min SDK 3.0,因此它需要在AsyncTask上运行.谢谢您的帮助!:)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
satellite(); //satellite's image from main menu
}
//******satellite url
private void satellite() {
// TODO Auto-generated method stub
ImageView imgView =(ImageView)findViewById(R.id.satellite);
Drawable drawable = LoadImageFromWeb("http://www.pagasa.dost.gov.ph/wb/sat_images/satellite.gif");
imgView.setImageDrawable(drawable);
}
private Drawable LoadImageFromWeb(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;
}
}
Run Code Online (Sandbox Code Playgroud)