在壁画中预取图像

时间:2017-12-14 05:46:07

标签: android image prefetch fresco

我正在开发一个应用程序,它在recyclelerview中滚动之前预取图像列表。我按照建议尝试使用prefetchToBitmapCache。但它没有成功。请在下面的代码中告诉我出了什么问题。 如何在设置到适配器之前加载之前的图像。

  private void prepareMovieData() {

    Movie movie = new Movie("https://i.pinimg.com/736x/97/5d/42/975d42c0fded9edfbd7aace45a52534e--crossover-cartoons.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/736x/57/2d/a4/572da4b27e9e41bca5f74a5a7358f965--iphone-wallpaper-wallpaper-doraemon.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/originals/e3/16/9b/e3169b4d7baa13739c0e3fa00b493562.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/originals/94/9f/ee/949fee0b6e6fae851fa0e3a062c7c506.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/originals/5a/b9/91/5ab9913ab76af885faecb02d21423a6e.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/736x/d0/20/20/d020203c6485fa0a03509b9a2ad6e051--comic-movies-comic-books.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/originals/9f/c1/f9/9fc1f96aebd1357049e64cb84266c065.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/originals/4a/86/50/4a865068fa0a4780e7725088331079aa.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/originals/7a/1d/52/7a1d52974db26b9aec65d33123751e7d.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    movie = new Movie("https://i.pinimg.com/originals/f9/b3/93/f9b393df3acfde39504d20045c085f60.jpg", "Animation, Kids & Family");
    movieList.add(movie);

    new DoPrefetchTask().execute();
}
  

DoPrefetchTask

public class DoPrefetchTask extends AsyncTask<String, Void, String> {
    ProgressDialog ceProgressDialogs;

    DoPrefetchTask() {
        ceProgressDialogs = new ProgressDialog(MainActivity.this);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        ceProgressDialogs.show();
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            ImagePipeline imagePipeline = Fresco.getImagePipeline();
            for (Movie uri : movieList) {                    imagePipeline.prefetchToBitmapCache(ImageRequest.fromUri(uri.img), null);
            }
        } catch (Exception e) {
            android.util.Log.d("Error Gracevenkat 123", "" + e.toString());
        }
        return null;
    }
    @Override
    protected void onPostExecute(String result) {

        if (MainActivity.this != null && !isFinishing() && ceProgressDialogs != null) {
            ceProgressDialogs.dismiss();
            mAdapter.update(movieList);

        }
    }
}
  

我的适配器onBindViewHolder:

  @Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    Movie movie = moviesList.get(position);
    holder.title.setText(movie.txt);
holder.imageView.setImageURI(Uri.parse(movie.img));

}

0 个答案:

没有答案