java - 带有多个图像的幻灯片放映?
问题描述
我想在幻灯片上制作具有不同图像的应用程序,我的代码如下:
@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”标题时,我的应用程序崩溃并出现错误:
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 文件中。在应用程序标签中。
推荐阅读
- web-hosting - 如何在 Oracle 云中添加我拥有的域并实时托管?
- php - VS Code 无法使用 PHP Intellsense
- ionic-framework - 用命令更新离子?
- opencv - 在制作 ROS 工作区时,没有规则制作目标 libopencv_calib3d.so.3.2.0 但安装了 opencv 3.4.1
- python - 如果测试失败,则停止/失败 docker build
- android - 将位图保存到 PNG 文件随机变黑
- python - 如何在 Keras 中为输入数据添加均匀分布的噪声?
- typo3 - TYPO3 如何使用正确的状态码在 404 上呈现页面
- php - 如何延长我的 Xdebug “会话时间”?
- reactjs - 应该使用什么方法来测试使用 Jest 的 SocketIO 客户端应用程序?