Nombre de animación desconocido: decelerateInterpolator
Android Studio 1.5 Device Samsung 4.4.2
Estoy intentando animar los artículos cargados de un ArrayList en un recyclerview. Cuando se hace clic en la flecha desplegable, los elementos deben animarse (desacelerar) cuando se expanden y deben animarse cuando se colapsan. Sin embargo, actualmente los elementos de la lista sólo aparecen.
Código que llama a setAnimation
- Animar dos elementos desplegables en capas Pre-Honeycomb
- ¿Por qué mi vista de diseño anima su tamaño antes de que su hermano haya cambiado su tamaño?
- Animaciones de transición de actividad en Android
- Cómo implementar la animación de texto de lista personalizada
- Cómo girar / voltear androide imageView?
@Override public void onBindChildViewHolder(ChatChildViewHolder childViewHolder, int position, Object childListItem) { ChatChildTitles chatChildTitles = (ChatChildTitles)childListItem; childViewHolder.tvChildTitle.setText(chatChildTitles.getTitle()); setAnimation(childViewHolder.cvChildRooms, position); }
Código para configurar la animación
private void setAnimation(CardView viewToAnimate, int position) { Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.fade_in); animation.setInterpolator(mContext, android.R.anim.decelerate_interpolator); viewToAnimate.startAnimation(animation); }
Aquí hay un par de capturas de pantalla:
En el estado colapsado
Después de hacer clic en la flecha expland la lista
Este es mi diseño que estoy usando que representa las filas que se mostrarán en el recicladorVer:
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView android:id="@+id/cvChildRooms" xmlns:card="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" card:cardBackgroundColor="@color/child_header_lighter_grey" card:contentPadding="4dp" card:cardPreventCornerOverlap="true"> <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/profile_image" android:layout_width="40dp" android:layout_height="40dp" android:layout_gravity="center_vertical|start" android:src="@drawable/photorace"/> <TextView android:id="@+id/tvChildTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center" android:text="Coffee Latte Room" android:fontFamily="sans-serif-light" android:textSize="16sp" android:textColor="@android:color/black"/> </android.support.v7.widget.CardView>
Tengo una función que debe comenzar la animación.
private void setAnimation(CardView viewToAnimate, int position) { Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.decelerate_interpolator); viewToAnimate.startAnimation(animation); }
He probado con lo siguiente que funciona bien con slide_in_left
. Sin embargo, no quiero que se deslice desde la izquierda
Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.slide_in_left); viewToAnimate.startAnimation(animation);
Muchas gracias por las sugerencias,
- Cómo animar una vista con la animación de Google Translate en Android
- animation.start () o animation.startNow () no inicia la animación inmediatamente
- Cómo girar el botón de acción flotante sin girar la sombra?
- Android animate () withEndAction () vs setListener () onAnimationEnd ()
- Cómo ampliar el espacio entre RecyclerView Item mientras se desplaza
- Facebook lide slideout menu (No utiliza esa biblioteca)
- Haga que aparezca un diseño con animación después de hacer clic en el botón en Android
- SearchView Expandir / contraer la animación en Android
Si desea utilizar un interpolador de desaceleración , debe configurarlo como un interpolador, no como el animador :
private void setAnimation(CardView viewToAnimate, int position) { Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.fade_in); //change this with your desidered (or custom) animation animation.setInterpolator(mContext, android.R.anim.decelerate_interpolator); viewToAnimate.startAnimation(animation); }
ACTUALIZAR
Usted dijo que está usando com.bignerdranch.android:expandablerecyclerview:2.0.3 .
De los documentos oficiales de la biblioteca, se indica claramente cómo crear animaciones de expansión / contracción :
También puede crear sus propias animaciones para la expansión reemplazando
ParentViewHolder#onExpansionToggled(boolean)
, que se llamará para usted cuando el itemView se expande o contrae.
Le sugiero que eche un vistazo al ejemplo oficial de la biblioteca.
No puedes usar decelerate_interpolator
porque no es una animación, es un interpolador:
Un interpolador define la velocidad de cambio de una animación. Esto permite acelerar, desacelerar, repetir los efectos básicos de animación (alpha, scale, translate, rotate), etc.
Referencia:
http://developer.android.com/reference/android/view/animation/Interpolator.html
Como puede ver el XML que describen son completamente diferentes:
Fuente de decelerate_interpolator.xml
:
<decelerateInterpolator />
Fuente de slide_in_left.xml
:
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="-50%p" android:toXDelta="0" android:duration="@android:integer/config_mediumAnimTime"/> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="@android:integer/config_mediumAnimTime" /> </set>
Para animar la lista a medida que se expanden y se contraen, considere el uso de un ItemAnimator de android.
Tendrás que configurar un itemAnimator personalizado, algo similar al del siguiente enlace:
https://gist.github.com/ademar111190/dc988c8d899dae0193f7
Establezca el itemAnimator en el método runPendingAnimations a su interpolador de desaceleración.
@Override public void runPendingAnimations() { if (!mViewHolders.isEmpty()) { int animationDuration = 300; AnimatorSet animator; View target; for (final RecyclerView.ViewHolder viewHolder : mViewHolders) { target = viewHolder.itemView; target.setPivotX(target.getMeasuredWidth() / 2); target.setPivotY(target.getMeasuredHeight() / 2); animator = new AnimatorSet(); animator.playTogether( ObjectAnimator.ofFloat(target, "translationX", -target.getMeasuredWidth(), 0.0f), ObjectAnimator.ofFloat(target, "alpha", target.getAlpha(), 1.0f) ); animator.setTarget(target); animator.setDuration(animationDuration); animator.setInterpolator(new DecelerateInterpolator()); animator.setStartDelay((animationDuration * viewHolder.getPosition()) / 10); animator.addListener(new AnimatorListener() { @Override public void onAnimationEnd(Animator animation) { mViewHolders.remove(viewHolder); } }); animator.start(); } } }
Entonces necesitará establecer el itemAnimator en la vista del reciclador.
RecyclerView.setItemAnimator (nuevo MyItemAnimator ());
Puede utilizar el código a continuación para hacer eso.
private void hideViews() { recyclerView.animate().translationY(-recyclerView.getHeight()).setInterpolator(new AccelerateInterpolator(2)); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFabButton.getLayoutParams(); int fabBottomMargin = lp.bottomMargin; mFabButton.animate().translationY(mFabButton.getHeight()+fabBottomMargin).setInterpolator(new AccelerateInterpolator(2)).start(); } private void showViews() { recyclerView.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)); mFabButton.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start(); }
Puede llamar a este método onClick de su botón.
Espero que te ayude.
- Problema de renderizado para Android con Intellij 13.1.3
- Cómo proporcionar opción para seleccionar wi-fi o GPRS para la conectividad de red en la aplicación android