0

I have about 90 pngs that I want to show them as an animation in my android app. I tried using animation list but the app uses about 120 MB of memory! I searched for more efficient ways and I found some solutions with openGL. The problem is I don't have any idea how to use openGL to do that and I don't know any thing about opengl! Is there any guide? How should I do that ?

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">

    <item android:duration="34" android:drawable="@drawable/a1"/>
    <item android:duration="34" android:drawable="@drawable/a2"/>
    <item android:duration="34" android:drawable="@drawable/a3"/>
    .
    .
    .
    <item android:duration="34" android:drawable="@drawable/a90"/>
    <item android:duration="34" android:drawable="@drawable/a91"/>

</animation-list>

my ImageView:

 <ImageView
        android:id="@+id/iv_loading_animation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:scaleType="centerInside"
        android:background="@drawable/loading_animation"/>

Main activity:

ImageView animationLoaderIv = (ImageView)rootView.findViewById(R.id.iv_loading_animation);

        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams)animationLoaderIv.getLayoutParams();
        layoutParams.height = width;
        layoutParams.width = width;
        animationLoaderIv.setLayoutParams(layoutParams);

        ((AnimationDrawable)animationLoaderIv.getBackground()).start();
genpfault
  • 51,148
  • 11
  • 85
  • 139
Soroosh
  • 543
  • 1
  • 4
  • 21
  • If you have to load all those images even in opengl , I do not think using opengl will reduce your app size. If you will be able to use fewer images and tween/animate them to achieve your animation result , then in that case it will be helpful using opengl . Can youalso share the use case of your app or at least this animation ? – Jimmy Mar 12 '18 at 19:22
  • yes it is a loading progress bar. – Soroosh Mar 12 '18 at 19:27
  • to have to add more than 100mb of images just for loading progress might be overkill. Also adding opengl support only for loading might be too much ( just an opinion). If just showing circular loading image is fine, then you can do it without adding any images. If you need your custom one, I suggest you to create gif and us it instead – Jimmy Mar 12 '18 at 19:31
  • Actually my Image are Just 2 MB !!! Is there any way to show GIF in android?! I don't think so. – Soroosh Mar 12 '18 at 19:41
  • you can try glide . This thread says it works https://stackoverflow.com/questions/31082330/show-gif-file-with-glide-image-loading-and-caching-library – Jimmy Mar 12 '18 at 19:54

0 Answers0