Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用bitmapTools的display方法在ListView中加载多张图片时,存在上下滑动时中间部分的图片会消失的问题 #3

Open
sanchips opened this issue Jul 25, 2015 · 4 comments

Comments

@sanchips
Copy link

No description provided.

@bacy
Copy link
Owner

bacy commented Jul 27, 2015

是否图片过大,代码中display的时候没有传入高宽?

@sanchips
Copy link
Author

加载14张网络图片,大小均为20K左右,排除图片过大的原因;使用四个参数的display方法传入宽高,在上下滑动的时候还是存在同样的问题。且重复滑动,消失图片的位置不同。怀疑是否为使用弱引用而没有使用LruCache的原因?

@bacy
Copy link
Owner

bacy commented Jul 29, 2015

代码中并没有使用弱引用来做缓存,是否方便提供部分代码?我本地测试一下

@sanchips
Copy link
Author

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;

public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.RecycleViewHolder> {

private Context context;
private ArrayList<String> strings;

public RecycleAdapter(Context context, ArrayList<String> strings) {
    this.context = context;
    this.strings = strings;
}

@Override
public RecycleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(context).inflate(R.layout.recycle_item, parent, false);
    RecycleViewHolder holder = new RecycleViewHolder(view);
    return holder;
}

@Override
public void onBindViewHolder(RecycleViewHolder holder, int position) {
    MyApplication.getInstance().getBitmapTools().display(holder.img, strings.get(position));
}

@Override
public int getItemCount() {
    return strings.size();
}

public class RecycleViewHolder extends RecyclerView.ViewHolder {

    ImageView img;

    public RecycleViewHolder(View itemView) {
        super(itemView);
        img = (ImageView) itemView.findViewById(R.id.img);
    }
}

}

public class MainActivity extends ActionBarActivity {

private RecyclerView recyclerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ArrayList<String> strings = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        strings.add("http://g.hiphotos.baidu.com/image/w%3D310/sign=972b9e33324e251fe2f7e2f99786c9c2/0824ab18972bd407e3e5eff479899e510fb3099c.jpg");
        strings.add("http://g.hiphotos.baidu.com/image/w%3D310/sign=0c1aeb23aad3fd1f3609a43b004f25ce/38dbb6fd5266d01687b5e625952bd40735fa350a.jpg");
        strings.add("http://h.hiphotos.baidu.com/image/w%3D310/sign=42c9b52c9925bc312b5d07996ede8de7/9e3df8dcd100baa1a22d27594710b912c9fc2eca.jpg");
        strings.add("http://a.hiphotos.baidu.com/image/w%3D310/sign=7b4616d4a964034f0fcdc4079fc27980/b999a9014c086e062d28e74200087bf40ad1cb33.jpg");
        strings.add("http://c.hiphotos.baidu.com/image/w%3D310/sign=3915003f9045d688a302b4a594c37dab/024f78f0f736afc383d9f669b119ebc4b64512e1.jpg");
        strings.add("http://e.hiphotos.baidu.com/image/w%3D310/sign=6366c3f20846f21fc9345852c6256b31/96dda144ad345982061b689b0ef431adcbef8422.jpg");
        strings.add("http://c.hiphotos.baidu.com/image/w%3D310/sign=612b97dcfd039245a1b5e70eb795a4a8/aa64034f78f0f7360d262d100b55b319eac413c2.jpg");
    }
    recyclerView = (RecyclerView) findViewById(R.id.recycle);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setAdapter(new RecycleAdapter(this, strings));
}

}

布局就不展示了,随便写一个就行。进入页面之后请上下重复滑动,中间部分有几张图片会消失。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants