Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用AQuery快速滚动时,ListView中的ImageView在错误位置可见_Android_Android Listview - Fatal编程技术网

Android 使用AQuery快速滚动时,ListView中的ImageView在错误位置可见

Android 使用AQuery快速滚动时,ListView中的ImageView在错误位置可见,android,android-listview,Android,Android Listview,我在listView的适配器中获得了以下getView: @Override public View getView(int position, View convertView, ViewGroup viewGroup) { View view = convertView; if (view == null) { view = LayoutInflater.from(context).inflate(R.layout.item_message, null

我在listView的适配器中获得了以下getView:

    @Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
    View view = convertView;
    if (view == null) {
        view = LayoutInflater.from(context).inflate(R.layout.item_message, null);
    }

    final Message msg = getItem(position);
    final AQuery aq = new AQuery(view);

    aq.id(R.id.message_baloon).background(myMessage ? R.drawable.chat_message_own : R.drawable.chat_message_other);

    // shared image
    if (msg.getPhotos() != null && msg.getPhotos().size() != 0) {
        aq.id(R.id.sent_photo).visible();
        aq.image(msg.getPhotos().get(0).getUrl(), true, true, 540, R.drawable.room_details_gallery_placeholder);
        aq.clicked(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //show fullsecreen photo
            }
        });

    } else {
        aq.id(R.id.sent_photo).gone();            
    }

    if (msg.getText() == null || msg.getText().length() == 0) {
        aq.id(R.id.message).gone();
    } else {
        aq.id(R.id.message).text(msg.getText());
        aq.id(R.id.message).visible();
    }

    return view;
}
该方法实际上较长,但此部分包含与该ImageView相关的所有内容。因此,正如标题所述,当滚动速度非常快时,带有“R.id.sent_photo”的ImageView在没有照片的位置可见,并且不会持续一秒钟,它仍然可见(我使用的是AndroidQuery库)


谢谢大家!

我遇到了同样的问题,所以,我在自定义适配器中使用了以下方法,我得到了解决方案

在ListViewItemsAdapter中添加以下方法:

@Override
    public int getCount() {
        return alUpgradeTour.size();
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public int getViewTypeCount() {

        return getCount();
    }

试试看,你也会得到解决方案。

试试看,AndroidQuery库在下载之前似乎没有放置占位符图像

    if (msg.getPhotos() != null && msg.getPhotos().size() != 0) {
        aq.id(R.id.sent_photo).visible();
        aq.id(R.id.sent_photo).setImageResource(R.drawable.room_details_gallery_placeholder);
        aq.image(msg.getPhotos().get(0).getUrl(), true, true, 540, R.drawable.room_details_gallery_placeholder);
        aq.clicked(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //show fullsecreen photo
            }
        });

    } else {
        aq.id(R.id.sent_photo).gone();
    }

解决方案未使用内存缓存: aq.image(msg.getPhotos().get(0.getUrl(),false,true,540,R.drawable.room\u details\u gallery\u占位符)

AndroidQuery沿着该图像函数执行以下操作

public static void async(Activity act, Context context, ImageView iv, String url, boolean memCache, boolean fileCache, int targetWidth, int fallbackId, Bitmap preset, int animation, float ratio, float anchor, Object progress, AccountHandle ah, int policy, int round, HttpHost proxy, String networkUrl){

    Bitmap bm = null;

    if(memCache){
        bm = memGet(url, targetWidth, round);
    }

    if(bm != null){
        iv.setTag(AQuery.TAG_URL, url);     
        Common.showProgress(progress, url, false);
        setBmAnimate(iv, bm, preset, fallbackId, animation, ratio, anchor, AjaxStatus.MEMORY);
    }else{
        Bit...
因此,如果它从memCache获得位图,它将调用setBmAnimate

private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source){
    bm = filter(iv, bm, fallback);...
过滤器是:

    private static Bitmap filter(View iv, Bitmap bm, int fallback){
    //ignore 1x1 pixels
    if(bm != null && bm.getWidth() == 1 && bm.getHeight() == 1 && bm != empty){        
        bm = null;
    }

    if(bm != null){
        iv.setVisibility(View.VISIBLE);
    }else if(fallback == AQuery.GONE){
        iv.setVisibility(View.GONE);
    }else if(fallback == AQuery.INVISIBLE){
        iv.setVisibility(View.INVISIBLE);
    }

    return bm;

这难道不等于每次调用getView时都对视图进行充气吗?实际上,对于每个位置,它都会进行充气,然后仅对该位置进行循环,对吗?对每个位置进行充气都会有所帮助。但这是一个非常糟糕的解决方案,而且速度非常慢,不实用。似乎您没有使用视图固定器进行查看,我相信如果您使用视图固定器,您的问题将得到解决,有很多文档可用。使用视图固定器可以解决您的问题。了解它。持视图者如何阻止aQuery在使用时使视图可见?(先看我的答案)不。我发现了这个问题,如果使用memCache,它会使ImageView可见。我会发布一个答案。