Android - inAnimation works for ViewFlipper, but outAnimation does not

I am trying to implement ViewFlipper and its translational animation. There are many pages that I can link to, but no matter how much I try, I don't see what ever happens. Below is my project, and there is currently no translation of the animation, but IF I COMMENT outside vf.setOutAnimation ... part, inAnimation the animation suddenly starts working .... Why?

package com.example.testview; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.animation.AnimationUtils; import android.widget.TextView; import android.widget.ViewFlipper; public class TestViewActivity extends Activity implements OnTouchListener { private ViewFlipper vf; private float firstTouchX; private float leaveTouchX; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); vf = (ViewFlipper) findViewById(R.id.viewFlipper1); vf.setOnTouchListener(this); } public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: firstTouchX = event.getX(); break; case MotionEvent.ACTION_UP: leaveTouchX = event.getX(); if (this.firstTouchX - 50f > leaveTouchX) { vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_in)); vf.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out)); vf.showNext(); } if (this.firstTouchX + 50f < leaveTouchX) { vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in)); vf.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out)); vf.showPrevious(); } break; } return true; } } 

Res / anim / left_in.xml:

 <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="350" android:fromXDelta="-100%p" android:toXDelta="0%p" android:fromYDelta="0%p" android:toYDelta="0%p"> </translate> 

Res / anim / left_out.xml:

 <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="350" android:fromXDelta="0%p" android:toXDelta="-100%p" android:fromYDelta="0%p" android:toYDelta="0%p"> </translate> 

Res / anim / right_in.xml:

 <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="350" android:fromXDelta="100%p" android:toXDelta="0%p" android:fromYDelta="0%p" android:toYDelta="0%p"> </translate> 

Res / anim / right_out.xml:

 <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="350" android:fromXDelta="0%p" android:toXDelta="100%p" android:fromYDelta="0%p" android:toYDelta="0%p"> </translate> 

Res / layout / main.xml

 <?xml version="1.0" encoding="utf-8"?> <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/viewFlipper1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <include android:id="@+id/first" layout="@layout/first" /> <include android:id="@+id/second" layout="@layout/second" /> <include android:id="@+id/third" layout="@layout/third" /> </ViewFlipper> 

first.xml / second.xml / third.xml (only their own image id is different)

 <?xml version="1.0" encoding="utf-8"?> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/img"> </ImageView> 

BIG EDITING . I am just creating a smaller project based on my post and it seems to work ... maybe in the process of omitting some codes that I thought was not necessary to start the discussion, it caused my problem .... I really sorry if someone tried to answer. I will do another survey and hope that I can post a breakdown that may be useful for subsequent links, unless the mods remove this question.

BIG EDIT2 . Today I tried again, and it DOES NOT WORK, apparently because I used the Android ARM 2.2 emulator. As soon as I switch to ARM / Inter 2.3.3, it works.

+4
source share
1 answer

Try this, replace outAnimation with inAnimation, e.g.

  if (this.firstTouchX - 50f > leaveTouchX) { vf.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out)); vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_in)); vf.showNext(); } if (this.firstTouchX + 50f < leaveTouchX) { vf.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out)); vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in)); vf.showPrevious(); } break; 

And then try, maybe it will work!

0
source

Source: https://habr.com/ru/post/1412235/


All Articles