【问题标题】:Only single image is loading in viewpagerviewpager 中仅加载单个图像
【发布时间】:2017-03-27 12:20:33
【问题描述】:

在我的 viewpager 的一页中,有 3 张图片来自后端。但是只有第一个图像正在加载其余图像没有加载。我在 onstart 中调试图像名称,图像名称来自 Android Monitor。

我的图像片段 xml 如下所示

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

  <ImageView
    android:id="@+id/imgfragment_imageview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY"
    android:src="@mipmap/ic_launcher"
    android:background="#000000" />

</LinearLayout>

对应的java文件如下所示

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.io.File;
import in.creace.magdreams.MagdreamsApplication;
import in.creace.magdreams.R;

public class ImageFragment extends Fragment{
   private View mView;
   private ImageView image;
   @Override
   public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mView=inflater.inflate(R.layout.layout_imagefragment, null);
    return mView;
}

@Override
public void onStart() {
    String path=getArguments().getString("IMAGEPATH");
    image=(ImageView) mView.findViewById(R.id.imgfragment_imageview);
    File file = new File(path);
    MagdreamsApplication.getInstance().getAquery().id(image).image(file,400);
    super.onStart();
  }
}

请查看我的代码。我在这段代码中有什么错误吗?如果代码有错误请更正

【问题讨论】:

  • 什么是 MagdreamsApplication,它在做什么?
  • 它是一个公共类,仅用于为查询提供实例...我也使用 glide 代替,但发生了同样的问题
  • 这个API不太好理解。但我可以看到 - 你只加载一张图片。那么如何获取其他的呢?
  • 每次图像视图到来时,图像就像热点一样,用相应的路径调用类。上面的图像有3个图像热点,所以从父类我们调用这个类3次。每次图片的url也传过来了……三张图片的url都来了……我登录了
  • 附加所有代码,以及相应的viewpager内容。

标签: android android-viewpager imageview


【解决方案1】:

这可能是由于堆大小或内存问题而发生的。您可以使用以下方法解决它:

1 - 任何图片库,例如 picasso 或 glide(最常用)

2- 下载图片并使用Base64压缩并显示图片

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 2018-01-28
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多