Slide show with multiple image?

自作多情 提交于 2021-01-29 05:40:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!