proble in drawing animation

Put your problem here if it does not fit any of the other categories.

proble in drawing animation

Postby ekambresh » Fri Feb 29, 2008 9:28 am

i am drawing a splash screen, for which i have draw 8-9 png images,in a interval of 5 sec.

regards
ekambresh
ekambresh
ekambresh
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Feb 08, 2008 8:54 am
Location: Bangalore

Top

Postby ekambresh » Fri Feb 29, 2008 12:33 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.cell.android.CellStory;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.widget.ImageView;
  10.  
  11.  
  12.  
  13. public class CellStory extends Activity implements Runnable {
  14.  
  15.        
  16.  
  17.         Thread t = null;
  18.  
  19.        
  20.  
  21.     public void onCreate(Bundle icicle) {
  22.  
  23.         super.onCreate(icicle);
  24.  
  25.         setContentView(R.layout.main);      
  26.  
  27.         t = new Thread(this);
  28.  
  29.     }
  30.  
  31.     public void run()
  32.  
  33.     {  
  34.  
  35.         drawSplashScreen();
  36.  
  37.     }
  38.  
  39.     int counter = 0;
  40.  
  41.     public void drawSplashScreen()
  42.  
  43.     {
  44.  
  45.          ImageView image =new ImageView(this);
  46.  
  47.         switch(counter)
  48.  
  49.         {
  50.  
  51.         case 1:
  52.  
  53.                  image.setImageDrawable(getResources().getDrawable(R.drawable.spl2));
  54.  
  55.                  image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  56.  
  57.                  image.setAdjustViewBounds(true);
  58.  
  59.                  counter++;
  60.  
  61.                  if(counter>=20)
  62.  
  63.                  {
  64.  
  65.                  image.setImageDrawable(getResources().getDrawable(R.drawable.spl1));
  66.  
  67.                  image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  68.  
  69.                  image.setAdjustViewBounds(true);
  70.  
  71.                  counter++;
  72.  
  73.                  }
  74.  
  75.                   if(counter>=40)
  76.  
  77.                  {
  78.  
  79.                  image.setImageDrawable(getResources().getDrawable(R.drawable.spl3));
  80.  
  81.                  image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  82.  
  83.                  image.setAdjustViewBounds(true);
  84.  
  85.                  counter++;
  86.  
  87.                  }
  88.  
  89.                 if(counter>=60)
  90.  
  91.                  {
  92.  
  93.                
  94.  
  95.                  image.setImageDrawable(getResources().getDrawable(R.drawable.spl4));
  96.  
  97.                  image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  98.  
  99.                  image.setAdjustViewBounds(true);
  100.  
  101.                  counter++;
  102.  
  103.                  }
  104.  
  105.                  if(counter>=80)
  106.  
  107.                  {
  108.  
  109.                  image.setImageDrawable(getResources().getDrawable(R.drawable.spl5));
  110.  
  111.                  image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  112.  
  113.                  image.setAdjustViewBounds(true);
  114.  
  115.                  counter++;
  116.  
  117.                  }
  118.  
  119.                  if(counter>=100)
  120.  
  121.                  {
  122.  
  123.                  image.setImageDrawable(getResources().getDrawable(R.drawable.spl6));
  124.  
  125.                  image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  126.  
  127.                  image.setAdjustViewBounds(true);
  128.  
  129.                  counter++;
  130.  
  131.                  System.out.print(counter);
  132.  
  133.                  }
  134.  
  135.                   if(counter>=120)
  136.  
  137.                  {
  138.  
  139.                         image.setImageDrawable(getResources().getDrawable(R.drawable.spl7));
  140.  
  141.                         image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  142.  
  143.                         image.setAdjustViewBounds(true);
  144.  
  145.                        
  146.  
  147.                  counter++;
  148.  
  149.                  }
  150.  
  151.                 if(counter>=140)
  152.  
  153.                  {
  154.  
  155.    
  156.  
  157.                         image.setImageDrawable(getResources().getDrawable(R.drawable.spl8));
  158.  
  159.                         image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  160.  
  161.                         image.setAdjustViewBounds(true);
  162.  
  163.                  counter++;
  164.  
  165.                  }
  166.  
  167.                  if(counter>=160)
  168.  
  169.                  {
  170.  
  171.                         image.setImageDrawable(getResources().getDrawable(R.drawable.spl9));
  172.  
  173.                         image.setScaleType(ImageView.ScaleType.FIT_CENTER);
  174.  
  175.                         image.setAdjustViewBounds(true);
  176.  
  177.                  counter++;
  178.  
  179.                  }
  180.  
  181.                  break;
  182.  
  183.         }
  184.  
  185.     }
  186.  
  187. }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4



main.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:orientation="vertical"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent"
  10.  
  11.    >
  12.  
  13. <TextView  
  14.  
  15.    android:id="@+id/key"
  16.  
  17.    android:layout_width="fill_parent"
  18.  
  19.    android:layout_height="wrap_content"
  20.  
  21.    android:text=""
  22.  
  23.    >
  24.  
  25.     </TextView>
  26.  
  27.    
  28.  
  29.    
  30.  
  31. <ImageView
  32.  
  33. android:id="@+id/image"
  34.  
  35.  
  36.  
  37. android:layout_centerVertical="true"
  38.  
  39.  
  40.  
  41. android:layout_centerHorizontal="true"
  42.  
  43.  
  44.  
  45. android:layout_width="300.0sp"
  46.  
  47.  
  48.  
  49. android:layout_height="400.0sp"
  50.  
  51.  
  52.  
  53. android:src="@drawable/spl2"
  54.  
  55.  
  56.  
  57. android:layout_x="500.0sp"
  58.  
  59.  
  60.  
  61. android:layout_y="550.0sp"
  62.  
  63.  
  64.  
  65. >
  66.  
  67.  
  68.  
  69. </ImageView>
  70.  
  71.  
  72.  
  73. <ImageView
  74.  
  75. android:id="@+id/image"
  76.  
  77.  
  78.  
  79. android:layout_centerVertical="true"
  80.  
  81.  
  82.  
  83. android:layout_centerHorizontal="true"
  84.  
  85.  
  86.  
  87. android:layout_width="300.0sp"
  88.  
  89.  
  90.  
  91. android:layout_height="400.0sp"
  92.  
  93.  
  94.  
  95. android:src="@drawable/spl1"
  96.  
  97.  
  98.  
  99. android:layout_x="500.0sp"
  100.  
  101.  
  102.  
  103. android:layout_y="550.0sp"
  104.  
  105.  
  106.  
  107. >
  108.  
  109. </ImageView>
  110.  
  111.  
  112.  
  113. <ImageView
  114.  
  115. android:id="@+id/image"
  116.  
  117.  
  118.  
  119. android:layout_centerVertical="true"
  120.  
  121.  
  122.  
  123. android:layout_centerHorizontal="true"
  124.  
  125.  
  126.  
  127. android:layout_width="300.0sp"
  128.  
  129.  
  130.  
  131. android:layout_height="400.0sp"
  132.  
  133.  
  134.  
  135. android:src="@drawable/spl3"
  136.  
  137.  
  138.  
  139. android:layout_x="500.0sp"
  140.  
  141.  
  142.  
  143. android:layout_y="550.0sp"
  144.  
  145.  
  146.  
  147. >
  148.  
  149. </ImageView>
  150.  
  151.  
  152.  
  153. <ImageView
  154.  
  155. android:id="@+id/image"
  156.  
  157.  
  158.  
  159. android:layout_centerVertical="true"
  160.  
  161.  
  162.  
  163. android:layout_centerHorizontal="true"
  164.  
  165.  
  166.  
  167. android:layout_width="300.0sp"
  168.  
  169.  
  170.  
  171. android:layout_height="400.0sp"
  172.  
  173.  
  174.  
  175. android:src="@drawable/spl4"
  176.  
  177.  
  178.  
  179. android:layout_x="500.0sp"
  180.  
  181.  
  182.  
  183. android:layout_y="550.0sp"
  184.  
  185.  
  186.  
  187. >
  188.  
  189. </ImageView>
  190.  
  191.  
  192.  
  193. <ImageView
  194.  
  195. android:id="@+id/image"
  196.  
  197.  
  198.  
  199. android:layout_centerVertical="true"
  200.  
  201.  
  202.  
  203. android:layout_centerHorizontal="true"
  204.  
  205.  
  206.  
  207. android:layout_width="300.0sp"
  208.  
  209.  
  210.  
  211. android:layout_height="400.0sp"
  212.  
  213.  
  214.  
  215. android:src="@drawable/spl5"
  216.  
  217.  
  218.  
  219. android:layout_x="500.0sp"
  220.  
  221.  
  222.  
  223. android:layout_y="550.0sp"
  224.  
  225.  
  226.  
  227. >
  228.  
  229. </ImageView>
  230.  
  231.  
  232.  
  233. <ImageView
  234.  
  235. android:id="@+id/image"
  236.  
  237.  
  238.  
  239. android:layout_centerVertical="true"
  240.  
  241.  
  242.  
  243. android:layout_centerHorizontal="true"
  244.  
  245.  
  246.  
  247. android:layout_width="300.0sp"
  248.  
  249.  
  250.  
  251. android:layout_height="400.0sp"
  252.  
  253.  
  254.  
  255. android:src="@drawable/spl6"
  256.  
  257.  
  258.  
  259. android:layout_x="500.0sp"
  260.  
  261.  
  262.  
  263. android:layout_y="550.0sp"
  264.  
  265.  
  266.  
  267. >
  268.  
  269. </ImageView>
  270.  
  271.  
  272.  
  273. <ImageView
  274.  
  275. android:id="@+id/image"
  276.  
  277.  
  278.  
  279. android:layout_centerVertical="true"
  280.  
  281.  
  282.  
  283. android:layout_centerHorizontal="true"
  284.  
  285.  
  286.  
  287. android:layout_width="300.0sp"
  288.  
  289.  
  290.  
  291. android:layout_height="400.0sp"
  292.  
  293.  
  294.  
  295. android:src="@drawable/spl7"
  296.  
  297.  
  298.  
  299. android:layout_x="500.0sp"
  300.  
  301.  
  302.  
  303. android:layout_y="550.0sp"
  304.  
  305.  
  306.  
  307. >
  308.  
  309. </ImageView>
  310.  
  311.  
  312.  
  313. <ImageView
  314.  
  315. android:id="@+id/image"
  316.  
  317.  
  318.  
  319. android:layout_centerVertical="true"
  320.  
  321.  
  322.  
  323. android:layout_centerHorizontal="true"
  324.  
  325.  
  326.  
  327. android:layout_width="300.0sp"
  328.  
  329.  
  330.  
  331. android:layout_height="400.0sp"
  332.  
  333.  
  334.  
  335. android:src="@drawable/spl7"
  336.  
  337.  
  338.  
  339. android:layout_x="500.0sp"
  340.  
  341.  
  342.  
  343. android:layout_y="550.0sp"
  344.  
  345.  
  346.  
  347. >
  348.  
  349. </ImageView>
  350.  
  351.  
  352.  
  353. <ImageView
  354.  
  355. android:id="@+id/image"
  356.  
  357.  
  358.  
  359. android:layout_centerVertical="true"
  360.  
  361.  
  362.  
  363. android:layout_centerHorizontal="true"
  364.  
  365.  
  366.  
  367. android:layout_width="300.0sp"
  368.  
  369.  
  370.  
  371. android:layout_height="400.0sp"
  372.  
  373.  
  374.  
  375. android:src="@drawable/spl8"
  376.  
  377.  
  378.  
  379. android:layout_x="500.0sp"
  380.  
  381.  
  382.  
  383. android:layout_y="550.0sp"
  384.  
  385.  
  386.  
  387. >
  388.  
  389. </ImageView>
  390.  
  391.  
  392.  
  393. <ImageView
  394.  
  395. android:id="@+id/image"
  396.  
  397.  
  398.  
  399. android:layout_centerVertical="true"
  400.  
  401.  
  402.  
  403. android:layout_centerHorizontal="true"
  404.  
  405.  
  406.  
  407. android:layout_width="300.0sp"
  408.  
  409.  
  410.  
  411. android:layout_height="400.0sp"
  412.  
  413.  
  414.  
  415. android:src="@drawable/spl9"
  416.  
  417.  
  418.  
  419. android:layout_x="500.0sp"
  420.  
  421.  
  422.  
  423. android:layout_y="550.0sp"
  424.  
  425.  
  426.  
  427. >
  428.  
  429. </ImageView>
  430.  
  431. </LinearLayout>
Parsed in 0.013 seconds, using GeSHi 1.0.8.4
ekambresh
ekambresh
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Feb 08, 2008 8:54 am
Location: Bangalore

Postby plusminus » Fri Feb 29, 2008 5:06 pm

Hello ekambresh

:shock: you should have a look at androids Frame-By-Frame animations!
It works similar to this...

Define the frame-by-frame animation:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <frames id="selected" oneshot="false">
  2.  
  3.     <frame drawable="@drawable/wheel0" duration="50" />
  4.  
  5.     <frame drawable="@drawable/wheel1" duration="50" />
  6.  
  7.     <frame drawable="@drawable/wheel2" duration="50" />
  8.  
  9.     <frame drawable="@drawable/wheel3" duration="50" />
  10.  
  11.     <frame drawable="@drawable/wheel4" duration="50" />
  12.  
  13.     <frame drawable="@drawable/wheel5" duration="50" />
  14.  
  15.  </frames>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4

And here is the Java code to load and play this animation:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. // Load the ImageView that will host the animation and
  2.  
  3.  // set its background to our AnimationDrawable XML resource.
  4.  
  5.  ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
  6.  
  7.  img.setBackground(R.drawable.spin_animation);
  8.  
  9.  
  10.  
  11.  // Get the background, which has been compiled to an AnimationDrawable object.
  12.  
  13.  AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
  14.  
  15.  
  16.  
  17.  // Start the animation (looped playback by default).
  18.  
  19.  frameAnimation.start()
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

i tried with follownig code bt its giving exception,

Postby ekambresh » Mon Mar 03, 2008 11:34 am

can u please correct my code...



import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

public class SpScreen extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ImageView img = (ImageView)findViewById(R.id.key);
img.setBackground(R.anim.animation);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();

// Start the animation (looped playback by default).
frameAnimation.start();

}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
android:src="@+id/selected" />

</LinearLayout>

anmation.xml
<?xml version="1.0" encoding="UTF-8"?>
<frames id="@+id/selected" oneshot="false" >
<frame drawable="@drawable/spl1" duration="50" />
<frame drawable="@drawable/spl2" duration="50" />
<frame drawable="@drawable/spl3" duration="50" />
<frame drawable="@drawable/spl4" duration="50" />
<frame drawable="@drawable/spl5" duration="50" />
<frame drawable="@drawable/spl6" duration="50" />
<frame drawable="@drawable/spl7" duration="50" />
<frame drawable="@drawable/spl8" duration="50" />
</frames>
ekambresh
ekambresh
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Feb 08, 2008 8:54 am
Location: Bangalore

Updated code

Postby robisen » Mon Jun 23, 2008 10:33 pm

see here for a working example

http://www.twintechs.com/blog/wp-admin/post-new.php

sorry about the cross post blog but its just easier to post the code and eclipse project there. hopefully the example will show you what you need to be doing with the frame by frame animations

robi
robisen
Junior Developer
Junior Developer
 
Posts: 14
Joined: Thu Feb 21, 2008 10:57 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 21 guests