在Android中展开recyclerView时如何旋转图像

在Android中展开recyclerView时如何旋转图像,android,android-recyclerview,android-imageview,Android,Android Recyclerview,Android Imageview,在我的应用程序中,我希望展开和折叠回收视图 我可以展开和折叠recyclerView,为此我使用了这个库: 我想当点击recyclerView(展开或折叠)时旋转箭头图像 我在viewHolder类中编写以下代码,但不工作,也不旋转箭头图像 ParentViewHolder代码: public class seasonParentViewHolder extends GroupViewHolder { private TextView row_epGuideParent_Title,

在我的应用程序中,我希望展开折叠
回收视图

我可以展开和折叠
recyclerView
,为此我使用了这个

我想当点击
recyclerView
展开折叠)时旋转箭头图像
我在
viewHolder
类中编写以下代码,但不工作,也不旋转箭头图像
ParentViewHolder代码:

public class seasonParentViewHolder extends GroupViewHolder {

    private TextView row_epGuideParent_Title, row_epGuideParent_Count, row_epGuideParent_Date;
    private ImageView row_epGuideParent_arrowImg;

    public seasonParentViewHolder(View itemView) {
        super(itemView);
        row_epGuideParent_Title = (TextView) itemView.findViewById(R.id.row_epGuideParent_Title);
        row_epGuideParent_Count = (TextView) itemView.findViewById(R.id.row_epGuideParent_Count);
        row_epGuideParent_Date = (TextView) itemView.findViewById(R.id.row_epGuideParent_Date);
        row_epGuideParent_arrowImg = (ImageView) itemView.findViewById(R.id.row_epGuideParent_arrowImg);
    }

    public void setGenreTitle(ExpandableGroup title) {
        if (title instanceof ExpandableModel) {
            row_epGuideParent_Title.setText(title.getTitle());
            row_epGuideParent_Count.setText(((ExpandableModel) title).getCount());
            row_epGuideParent_Date.setText(((ExpandableModel) title).getDate());
        }
    }

    @Override
    public void expand() {
        animateExpand();
    }

    @Override
    public void collapse() {
        animateCollapse();
    }

    private void animateExpand() {
        RotateAnimation rotate =
                new RotateAnimation(360, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(300);
        rotate.setFillAfter(true);
        row_epGuideParent_arrowImg.setAnimation(rotate);
    }

    private void animateCollapse() {
        RotateAnimation rotate =
                new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(300);
        rotate.setFillAfter(true);
        row_epGuideParent_arrowImg.setAnimation(rotate);
    }
}
在库中调用展开和折叠:

public abstract class GroupViewHolder extends RecyclerView.ViewHolder implements OnClickListener {

  private OnGroupClickListener listener;

  public GroupViewHolder(View itemView) {
    super(itemView);
    itemView.setOnClickListener(this);
  }

  @Override
  public void onClick(View v) {
    if (listener != null) {
      if (listener.onGroupClick(getAdapterPosition())) {
        collapse();
      } else {
        expand();
      }
    }
  }

  public void setOnGroupClickListener(OnGroupClickListener listener) {
    this.listener = listener;
  }

  public void expand() {}

  public void collapse() {}

}

单击
回收视图
展开折叠)时,如何解决此问题并旋转箭头图像?

TL;DR您必须使用
startAnimation()
来查看
ImageView
而不是
setAnimation()

void setAnimation(动画)

设置要为此视图播放的下一个动画。如果你想要 要立即播放动画,请使用 取而代之的是startAnimation(android.view.animation.animation)[…]


(引自)

@Kir-只需在您的两种方法
expand()
collapse()
@Override
public void expand() {
    arrow_icn.setRotation(180);
}

@Override
public void collapse() {
    arrow_icn.setRotation(0);
}