Java 多图像幻灯片放映?
我想在幻灯片上制作具有不同图像的应用程序,我的代码如下所示:Java 多图像幻灯片放映?,java,android,slideshow,Java,Android,Slideshow,我想在幻灯片上制作具有不同图像的应用程序,我的代码如下所示: @NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) { inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.infla
@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;
}
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)
<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">
当我运行我的应用程序并点击“Vers la lune”标题时,我的应用程序崩溃,错误显示:
@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;
}
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)
<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">
错误来自这一行:
imageView.setImageResource(vers[position]);
我的清单代码如下所示:
@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;
}
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)
<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文件中。在应用程序标记中。这可能有效。
加上这个
android:largeHeap="true"
在Manifest.xml文件中。在应用程序标签中。有很多图像,这就是您的分配已满的原因。在其他设备上尝试可能不会收到此错误。或者尽量减少图片的大小,这也会有帮助。有很多图片,这就是为什么你的分配会满的原因。在其他设备上尝试可能不会收到此错误。或者尝试减小图像的大小,这也会有所帮助。您是否使用延迟加载?另外,向我们展示更多的代码,比如你的
R.layout.swipe
和vers
以及所有相关的java代码。你在使用延迟加载吗?另外,向我们展示更多的代码,比如你的R.layout.swipe
和vers
以及所有相关的java代码