android 滑动图像仅在向下滚动GridView后显示?

mrphzbgm  于 2022-12-25  发布在  Android
关注(0)|答案(1)|浏览(121)

我一直在摆弄tmdb和电影,我遇到了一个问题,当我的片段加载并填充我的gridview适配器时,图像的加载没有任何错误,但实际上我看不到它,直到我向下滚动GridView几行并再次备份。
图像显示滚动前的样子。然后滚动后所有其他图像出现。???
下面是我的GridView适配器代码。

package com.rwsw.livesofa.tv.gridviews;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.rwsw.livesofa.R;
import com.rwsw.livesofa.models.MovieModel;
import com.rwsw.livesofa.tv.fragments.FragmentRecommended;

import java.util.ArrayList;
import java.util.HashMap;

public class Grid_View_Recommended extends BaseAdapter {

    Context context;
    LayoutInflater inflater;
    private static ArrayList<MovieModel> movieModelList;
    MovieModel resultp;

    public Grid_View_Recommended(Context context, ArrayList<MovieModel> arraylist) {
        this.context = context;
        movieModelList = arraylist;
    }

    public class ViewHolder {
        public ImageView poster;
    }

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

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        View itemView = convertView;

        Grid_View_Recommended.ViewHolder holder;

        if (convertView == null) {
            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            itemView = inflater.inflate(R.layout.item_movie, parent, false);

            holder = new ViewHolder();
            holder.poster = (ImageView) itemView.findViewById(R.id.poster);

            itemView.setTag(holder);
        } else {
            holder = (Grid_View_Recommended.ViewHolder) itemView.getTag();
            resultp = movieModelList.get(position);

            Glide.with(context)
                    .asBitmap()
                    .load("https://image.tmdb.org/t/p/w342" + resultp.getPosterPath())
                    
                    .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                    .into(holder.poster);

        }

        return itemView;
    }

}

我做了很多搜索,并尝试加载为位图和使用不同的缓存策略的,但不能让它工作。

kgsdhlau

kgsdhlau1#

第一次加载列表视图时,null条件为true。如果您看到null条件中没有Glide代码,则图片仅在convertView不为null时加载。
所以你可以在两个部分都保留Glide代码。如果这样做不起作用,下面是一些你可以尝试的方法
1.直接加载

Glide.with(this)
       .load("https://image.tmdb.org/t/p/w342" + resultp.getPosterPath())
..into(holder.poster);

If that does not solve it. Change the DiskCacheStrategy to NONE

相关问题