http://hiphotos.baidu.com/yyq0125/pic/item/53616050a142b7320df3e352.jpg
这张图片(不能显示的图片中的一张),显示在一个Gallery中,但是始终显示不出来,不知道为什么
贴下代码:public class HandlerThreadTest extends Activity {
private String[] myURLs = {"http://hiphotos.baidu.com/stonecando/pic/item/a4889f0ff03b06de37d122ad.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/tl196605/pic/item/dc746cdb7e219ffdb7fd48a6.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/18kb/pic/item/c2a65d27314db90ec9955924.jpg",
"http://hiphotos.baidu.com/lao135798010/pic/item/d79c23d26d1e63393af3cfd1.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/275166424/pic/item/8264fc1932a26fd6ae51330a.jpg",
"http://hiphotos.baidu.com/yyq0125/pic/item/53616050a142b7320df3e352.jpg",
};
private ArrayList<Bitmap> imgList=new ArrayList<Bitmap>();
private ImageView iv;
private Gallery gallery;
private Handler handler;
private ProgressBar loadProgressBar;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
HandlerThread handlerThread = new HandlerThread("handler_thread");
handlerThread.start();
handler = new Handler();
updateUI();
}
public void updateUI(){
Thread t = new Thread(){ @Override
public void run() {
// TODO Auto-generated method stub
setBitmapFromWebsite(myURLs);
handler.post(new Runnable(){
public void run(){
gallery = (Gallery)findViewById(R.id.mobs);
gallery.setAdapter(new ImageAdapter(HandlerThreadTest.this));
//loadProgressBar = (ProgressBar)findViewById(R.id.loadProgressBar);
System.out.println("size=" + imgList.size());
//loadProgressBar.setEnabled(false);
}
});
}
};
t.start();
}
/**
* @param urls 图片网络地址数组
* @return 下载图片并存放在imgList中
* */
private void setBitmapFromWebsite(String[] urls){
imgList.clear();
for(int i = 0 ; i < urls.length ; i ++){
try {
URL url = new URL(urls[i]);
URLConnection conn = url.openConnection();
//conn.setRequestProperty("X-Online-Host", "hiphotos.baidu.com");
conn.connect();
InputStream in = conn.getInputStream();
BufferedInputStream bis= new BufferedInputStream(in);
Bitmap bm = BitmapFactory.decodeStream(bis);
imgList.add(bm);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(urls[i] + e.getMessage());
e.printStackTrace();
}
}
}
public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return imgList.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageBitmap(imgList.get(position));
System.out.println("set image imaList[" + position + "]");
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
return i;
}
private Context mContext;
}
}
这张图片(不能显示的图片中的一张),显示在一个Gallery中,但是始终显示不出来,不知道为什么
贴下代码:public class HandlerThreadTest extends Activity {
private String[] myURLs = {"http://hiphotos.baidu.com/stonecando/pic/item/a4889f0ff03b06de37d122ad.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/tl196605/pic/item/dc746cdb7e219ffdb7fd48a6.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/maozehongbd/pic/item/0417494248ee6c486963e570.jpg",
"http://hiphotos.baidu.com/18kb/pic/item/c2a65d27314db90ec9955924.jpg",
"http://hiphotos.baidu.com/lao135798010/pic/item/d79c23d26d1e63393af3cfd1.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/lenovode/pic/item/1c2a66c4b70c242e9c163d84.jpg",
"http://hiphotos.baidu.com/275166424/pic/item/8264fc1932a26fd6ae51330a.jpg",
"http://hiphotos.baidu.com/yyq0125/pic/item/53616050a142b7320df3e352.jpg",
};
private ArrayList<Bitmap> imgList=new ArrayList<Bitmap>();
private ImageView iv;
private Gallery gallery;
private Handler handler;
private ProgressBar loadProgressBar;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
HandlerThread handlerThread = new HandlerThread("handler_thread");
handlerThread.start();
handler = new Handler();
updateUI();
}
public void updateUI(){
Thread t = new Thread(){ @Override
public void run() {
// TODO Auto-generated method stub
setBitmapFromWebsite(myURLs);
handler.post(new Runnable(){
public void run(){
gallery = (Gallery)findViewById(R.id.mobs);
gallery.setAdapter(new ImageAdapter(HandlerThreadTest.this));
//loadProgressBar = (ProgressBar)findViewById(R.id.loadProgressBar);
System.out.println("size=" + imgList.size());
//loadProgressBar.setEnabled(false);
}
});
}
};
t.start();
}
/**
* @param urls 图片网络地址数组
* @return 下载图片并存放在imgList中
* */
private void setBitmapFromWebsite(String[] urls){
imgList.clear();
for(int i = 0 ; i < urls.length ; i ++){
try {
URL url = new URL(urls[i]);
URLConnection conn = url.openConnection();
//conn.setRequestProperty("X-Online-Host", "hiphotos.baidu.com");
conn.connect();
InputStream in = conn.getInputStream();
BufferedInputStream bis= new BufferedInputStream(in);
Bitmap bm = BitmapFactory.decodeStream(bis);
imgList.add(bm);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(urls[i] + e.getMessage());
e.printStackTrace();
}
}
}
public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return imgList.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageBitmap(imgList.get(position));
System.out.println("set image imaList[" + position + "]");
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
return i;
}
private Context mContext;
}
}
解决方案 »
- Android ListView滑动卡屏问题如何优化?????
- 现在有没有可以反编译出android应用中的本地代码的工具?
- Google Map API返回点击的点的经纬度(不是使用定位)
- 调用OnZoomChangeListener接口的onZoomChange方法
- 关于反编译akp。
- 新手请教如何在eclipse ADT可视环境下给按钮添加响应事件
- Android listview的问题,学生做项目,遇到点问题,求讲解。
- 又来问问题了。。。关于ObjectInputStream!
- android TimePickerDialog 的问题
- 路过的求助,android进程如何减小?
- HTML5写的播放器无法在Android模拟器上播放视频
- setAnimation 为什么设置动画后 只执行一次???
URL url = new URL(urls[i]);
URLConnection conn = url.openConnection();
//conn.setRequestProperty("X-Online-Host", "hiphotos.baidu.com");
conn.connect();
InputStream in = conn.getInputStream();
BufferedInputStream bis= new BufferedInputStream(in);
Bitmap bm = BitmapFactory.decodeStream(bis);
imgList.add(bm);原因是这块儿,bm == null,所以存到List里面的是空值,为什么呢?有的能下载,有的又不能下载,这些链接都能打开啊?
data stream is not available, then they return failure. I will investigate trying to support
this in the future.
找到原因了,补下