问题
I want to make app with different image on slide show and my code is below:
@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;
}
when I run my app and click on "Vers la lune" title my app crashed and error 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)
and error is from this line:
imageView.setImageResource(vers[position]);
My manifest code is below:
<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">
回答1:
This might work. Add this
android:largeHeap="true"
in your Manifest.xml file . In application tag .
来源:https://stackoverflow.com/questions/54997556/slide-show-with-multiple-image