Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No animation with ViewFlipper?

Tags:

android

I'm trying to use ViewFlipper to add an animation between views, as in following a tutorial on the subject. However, it just doesn't seem to want to work. It'll change the pages, but I get no animation -- even if I add a huge delay to push_left_in.

Here's my onCreate:


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        viewFlipper = (ViewFlipper)findViewById(R.id.flipper);
        viewFlipper.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
        mapView = (MapView)findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);
    }

push_left_in comes from the Google samples. Here's the trigger action:


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case R.id.button_map:
            viewFlipper.setDisplayedChild(0);
            return true;
        case R.id.button_conditions_general:
            viewFlipper.setDisplayedChild(1);
            return true;
(etc)

And my layout:


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

<LinearLayout android:id="@+id/mainlayout"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              xmlns:android="http://schemas.android.com/apk/res/android">

  <ViewFlipper android:id="@+id/flipper"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent">  

    <view class="com.google.android.maps.MapView"
          android:id="@+id/mapView"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:clickable="true"
          android:apiKey="MY_API_KEY"
          />

    <TableLayout
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:background="#ffffff"
                 android:stretchColumns="1"
                 >
      <TableRow>
        <TextView android:id="@+id/field1"
                  android:layout_column="1"        
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:textColor="#000000"
                  android:textStyle="bold"
                  android:textSize="18px"
                  android:text="@string/field1"
                  >
        </TextView>
        <EditText android:text="100"
                  android:id="@+id/field2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content">
        </EditText>
        <TextView android:id="@+id/field3"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:textColor="#000000"
                  android:textStyle="bold"
                  android:textSize="18px"
                  android:text="%"
                  >
        </TextView>
      </TableRow>
    </TableLayout>

  </ViewFlipper>
</LinearLayout>


Thoughts?

like image 631
Karen Avatar asked Aug 12 '10 23:08

Karen


1 Answers

Try setting your animations in the xml file instead.

  <ViewFlipper android:id="@+id/flipper"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:inAnimation="@anim/push_left_in"> 
like image 106
Nathan Schwermann Avatar answered Oct 21 '22 21:10

Nathan Schwermann