Creating the Activity

Start by creating the basic XML layout file for our test-animation activity screen (see Listing 6-1).

Listing 6-1. XML Layout File for the Animation Test Harness

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

<!-filename: /res/layout/frame_animations_layout.xml -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<TextView android:id="@+id/textViewId1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Debug Scratch Pad" />

<Button android:id="@+id/startFAButtonId" android:layout_width="fin_parent" android:layout_height="wrap_content" android:text="Start Animation"

<ImageView android:id="@+id/animationImage" android:layout_width="fill_parent" android:layout_height="wrap_content" />

</LinearLayout>

The first control is the debug-scratch text control, which is a simple TextView. You then add a button to start and stop the animation. The last view is the ImageView, where you will play the animation. Once you have the layout, create an activity to load this view (see Listing 6-2).

Listing 6-2. Activity to Load the ImageView public class FrameAnimationActivity extends Activity {

^Override public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState); setContentView(R.layout.frame_animations_layout);

You will be able to run this activity from any menu item you might have in your current application by executing the following code:

Intent intent = new Intent(inActivity,FrameAnimationActivity.class); inActivity.startActivity(intent);

At this point, you will see an activity that looks like the one in Figure 6-3.

Figure 6-3. Frame-by-frame animation activity
0 0

Post a comment