该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
通过okhttpclient3下载多种网络图片后,写入viewpager imageview中后,显示顺序不对。
public Object instantiateItem(@NonNull ViewGroup container, final int position) {
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
container.addView(imageView);
NewsCenterDetailBean.DataEntity.TopNewsEntity topNewsEntity = topnews.get(position);
String imageurl = Constants.BASE_URL + topNewsEntity.getTopimage();
request = new Request.Builder().url(imageurl).build();
call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
byte[] picture = response.body().bytes();
Bitmap map = BitmapFactory.decodeByteArray(picture,0,picture.length);
Message msg = new Message();
msg.what = 0;
msg.obj = map;
handler.sendMessage(msg);
}
});
return imageView;
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
topnewsBitmap = (Bitmap) msg.obj;
imageView.setImageBitmap(topnewsBitmap);
break
default:
break;
}
}
};