0

Hi i'm trying to start an AnimationDrawable with Bitmap contains in my phone memory like this :

public void startAnimation(JSONArray listImgGroup, RelativeLayout rl) throws JSONException {
        if (listImgGroup.length() > 0) {
            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
                for (int i = 0; i < listImgGroup.length(); i++) {
                    ImageView imgGroup = new ImageView(this);


                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) (metrics.widthPixels * listImgGroup.getJSONObject(i).getDouble("size_x")), (int) (metrics.heightPixels * listImgGroup.getJSONObject(i).getDouble("size_y")));
                    params.leftMargin = (int) (metrics.widthPixels * listImgGroup.getJSONObject(i).getDouble("position_x"));
                    params.topMargin = (int) (metrics.heightPixels * listImgGroup.getJSONObject(i).getDouble("position_y"));



                    JSONArray imgDic = listImgGroup.getJSONObject(i).getJSONArray("Img");
                    Log.i("IMG DICTIONNAIRE = ", "" + imgDic);

                    for (int j = 0; j < imgDic.length(); j++) {

                        //Bitmap bMap = BitmapFactory.decodeFile("/storage/sdcard0/saved_img/"+imgDic.getJSONObject(j).getString("name"));
                        animation = new AnimationDrawable();

                        animation.addFrame(new BitmapDrawable(getResources(), BitmapFactory.decodeFile("/storage/sdcard0/saved_img/"+imgDic.getJSONObject(j).getString("name"))), 1000);
                        animation.setCallback(imgGroup);
                        animation.start();
                        imgGroup.setImageDrawable(animation);
                        animation.setOneShot(false);
                        Log.i("NAME ANIMATION", imgDic.getJSONObject(j).getString("name"));
                    }
                    rl.addView(imgGroup, params);
                    animation.stop();
                }
            }

It works but i just see the second image in my AnimationDrawable. How can i see the first and animate the first to go to the second ? Thank you guy

Fcps
  • 335
  • 4
  • 19
  • you have many images you want to animate in 1 animation drawable ? – Lena Bru Mar 19 '14 at 07:28
  • @LenaBru Yes I have many images i want animate in 1 animation drawable – Fcps Mar 19 '14 at 07:38
  • then 1. why are you creating a new animation drawable with every iteration. 2. why are you stopping this animation drawable with every iteration ? 3. why are you setting it to oneShot(false) AFTER you've started animating ? – Lena Bru Mar 19 '14 at 07:42
  • please write in english what you want to achieve, and i will tell you how to do that – Lena Bru Mar 19 '14 at 07:46
  • @LenaBru I have a JSONArray of ImagesGroup and inside this ImagesGroup, I have a JSONArray of Img. Here is my Array of Img : – Fcps Mar 19 '14 at 13:18
  • can you write this inside your question body, in plain english , like "i have an array of images, i want to put it in a drawable , to animate at the start of some activity, i am using fragments or not using fragments to do it" – Lena Bru Mar 20 '14 at 17:54

0 Answers0