包含多个图像的幻灯片放映?

Slide show with multiple image?

我想在幻灯片放映时制作具有不同图像的应用,我的代码在下方:

    @NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.swipe, container, false);

    ImageView imageView = view.findViewById(R.id.swipe_imageView);
    TextView textView = view.findViewById(R.id.swipe_textView);

    if (CustomAdapterList.titleForOther.equalsIgnoreCase("Vers la lune"))
    {
        imageView.setImageResource(vers[position]);
    }
    else {
        imageView.setBackgroundResource(image[position]);
    }

    textView.setText(CustomAdapterList.titleForOther + "");

    container.addView(view);

    return view;
}

当我 运行 我的应用程序并单击 "Vers la lune" 标题时,我的应用程序崩溃并出现错误 says:

java.lang.OutOfMemoryError: Failed to allocate a 298650252 byte allocation with 12571136 free bytes and 238MB until OOM
    at dalvik.system.VMRuntime.newNonMovableArray(Native Method)

错误来自行:

imageView.setImageResource(vers[position]);

我的清单代码在下方:

<application
    android:allowBackup="true"
    android:hardwareAccelerated="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="false"
    android:theme="@style/AppTheme"
    android:largeHeap="true">

这可能有用。 添加此

 android:largeHeap="true" 

在您的 Manifest.xml 文件中。在应用程序标签中。