Android Studio 1.5
Device Samsung 4.4.2
我试图对从ArrayList加载到recyclerview中的项目进行动画处理。当单击下拉箭头时,项目应该在展开时减速动画(decelerate),在折叠时动画缩小。但是,目前列表项只是出现了。调用setAnimation的代码
@Override
public void onBindChildViewHolder(ChatChildViewHolder childViewHolder, int position, Object childListItem) {
ChatChildTitles chatChildTitles = (ChatChildTitles)childListItem;
childViewHolder.tvChildTitle.setText(chatChildTitles.getTitle());
setAnimation(childViewHolder.cvChildRooms, position);
}
设置动画的代码
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);
}
这里有一些截图:
在折叠状态下:
点击箭头后展开列表:
这是我正在使用的布局,代表将显示在recyclerView中的行:
<?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>
我有一个应该开始动画的函数。private void setAnimation(CardView viewToAnimate, int position) {
Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.decelerate_interpolator);
viewToAnimate.startAnimation(animation);
}
我已经测试过以下代码,使用slide_in_left
效果是可以的。 但是,我不想让它们从左侧滑入。
我已经测试过以下代码,使用slide_in_left
效果是可以的。但是,我不希望它们从左侧滑入。
Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.slide_in_left);
viewToAnimate.startAnimation(animation);
非常感谢任何提供建议的人,