开发者

No animation with ViewFlipper?

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">
        </Edi开发者_开发技巧tText>
        <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?


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"> 


You need to set In and Out animations separately. You can do it in XML:

<ViewFlipper
    android:id="@+id/view_flipper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:inAnimation="@anim/in_from_right"
    android:outAnimation="@anim/out_to_left">

or in code:

viewFlipper.setInAnimation(getActivity(), R.anim.in_from_right);
viewFlipper.setOutAnimation(getActivity(), R.anim.out_to_left);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜