Don't understand how to use animation with adapterViewFlipper

I do not understand how to use animation with adapterViewflipper. I am in API13 and I am using adapterViewFlipper in the fragment.

So, in my XML file, I only have:

<AdapterViewFlipper android:id="@+id/avfPicturesSite" android:layout_width="match_parent" android:layout_height="300dp" android:background="@drawable/gradientbackground" > </AdapterViewFlipper> 

and I dynamically create an ImageView in getView ().

 @Override public View getView(int position, View convertView, ViewGroup parent) { View view = null; if (convertView == null) { final ViewHolder viewHolder = new ViewHolder(); view = new ImageView(context); viewHolder.img = (ImageView) view; view.setTag(viewHolder); } else { view = convertView; } ViewHolder viewHolder = (ViewHolder)view.getTag(); viewHolder.img.setImageURI(getItem(position)); return view; } 

I view images using buttons, where I try to set the animation. SitePicturesFlipper.setInAnimation (context context, int resourceID) seems to be waiting for an AnimatorSet.

  nextSitePicture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { //sitePicturesFlipper.setInAnimation(R.animator.right_in); sitePicturesFlipper.setInAnimation(getActivity(), R.anim.left_in); sitePicturesFlipper.setOutAnimation(getActivity(), R.anim.right_out); sitePicturesFlipper.showNext(); } }); 

and animators are declared as follows:

left_in.xml

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="5000" android:fromXDelta="-100%" android:toXDelta="0%"/> <alpha android:duration="5000" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set> 

right_out.xml

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="5000" android:fromXDelta="0%" android:toXDelta="100%"/> <alpha android:duration="5000" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set> 

But when I click on the button, I get the animator name RuntimeException Unknown: translate!

I also tried using ObjectAnimator, for example:

  nextSitePicture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { sitePicturesFlipper.setInAnimation(getActivity(), R.animator.left_in); sitePicturesFlipper.setInAnimation(getActivity(), R.animator.right_out); sitePicturesFlipper.showNext(); } }); 

and xml files:

left_in2.xml

 <?xml version="1.0" encoding="utf-8"?> <set> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:propertyName="yFraction" android:valueType="floatType" android:valueFrom="-1" android:valueTo="0" android:duration="600"/> </set> 

right_out2.xml:

 <?xml version="1.0" encoding="utf-8"?> <set> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:propertyName="yFraction" android:valueType="floatType" android:valueFrom="0" android:valueTo="1" android:duration="600"/> </set> 

but in this case I get java.lang.ClassCastException: android.animation.AnimatorSet cannot be passed to android.animation.ObjectAnimator

So I don’t understand how to install and use it correctly, and it’s quite difficult to find an example using adapterViewFlipper on the Internet, except in Thai, but I don’t really like Thai ...

So how to use animation with adapterViewFlipper?

+1
source share
1 answer

Well, finally, I found that ObjectAnimator is an easy way to declare animations using adapterViewFlipper . In any case, he does not like the tags "<" set ">" and "<" / set ">" at least as I wrote them. And I did not find how to declare multiple property animations. I admit that I still have problems to really understand the documentation on Android ...

Waiting for information if anyone has an idea about this.

So, to solve the first problem I had, a complete set of ObjectAnimator for slide images left and right in adapterViewFlipper:

left_in.xml declared in the animator folder

 <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:propertyName="x" android:valueType="floatType" android:valueFrom="-1500" android:valueTo="0" android:duration="600"/> 

right_out.xml

 <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:propertyName="x" android:valueType="floatType" android:valueFrom="0" android:valueTo="1500" android:duration="600"/> 

right_in.xml

 <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:propertyName="x" android:valueType="floatType" android:valueFrom="1500" android:valueTo="0" android:duration="600"/> 

left_out.xml

 <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:propertyName="x" android:valueType="floatType" android:valueFrom="0" android:valueTo="-1500" android:duration="600"/> 

Then to use the animations:

  myAdapterViewFlipper.setInAnimation(getActivity(), R.animator.right_in); myAdapterViewFlipper.setOutAnimation(getActivity(), R.animator.left_out); myAdapterViewFlipper.showNext(); 

or

  myAdapterViewFlipper.setInAnimation(getActivity(), R.animator.left_in); myAdapterViewFlipper.setOutAnimation(getActivity(), R.animator.right_out); myAdapterViewFlipper.showPrevious(); 
+7
source

All Articles