Hi all

 I have a an activity which has an image view to
display animation. and I'm reading resources from res/anim which is
working absolutely fine.  But what I'm trying is to specify the frames
at run time instead of hard coding at the res/anim/file.xml  any idea. ?

 Following works fine.

    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         setContentView(R.layout.main);
         mImageView = (ImageView)this.findViewById(R.id.AdImageView);
         mImageView.setImageResource(R.anim.adlist);
         adDisplay = (AnimationDrawable)mImageView.getDrawable();
               }

     @Override
     public void onWindowFocusChanged(boolean hasFocus) {
         super.onWindowFocusChanged(hasFocus);
         if(hasFocus== true){
             adDisplay.start();
          }

 and the  adlist.xml is :

 <?xml version="1.0" encoding="UTF-8"?>

     <item android:drawable="@drawable/ad_01" android:duration="500" />
     <item android:drawable="@drawable/ad_02" android:duration="500" />
 </animation-list>

 But what I wan't is I wan't to create the AnimationDrawable object at
runtime not from the xml source,as my requirement is no of frames and
*.png files may change at the runtime.

 I tried the following it I'm unable to get the expected result.

 @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         mImageView = (ImageView)this.findViewById(R.id.AdImageView);
         adDisplay = new AnimationDrawable();
         
adDisplay.addFrame(Drawable.createFromPath("/data/data/com.example.ad/files 
/ad_01.png"),500 );
         
adDisplay.addFrame(Drawable.createFromPath("/data/data/com.example.ad/files 
/ad_02.png"),500 );
         mImageView.setImageDrawable(adDisplay);

               }

 Any thing I'm missing in the implementation ?


      Explore and discover exciting holidays and getaways with Yahoo! India 
Travel http://in.travel.yahoo.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to