发布
社区首页 >问答首页 >在Android中扩展recyclerView时如何旋转图像

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

Stack Overflow用户
提问于 2017-07-26 16:21:02
回答 2查看 1.6K关注 0票数 2

在我的应用程序中,我希望展开折叠 recyclerView

我可以展开和折叠recyclerView,并为此使用https://github.com/thoughtbot/expandable-recycler-view

我想当点击recyclerView (展开折叠)旋转箭头图像!

我在下面用viewHolder类编写代码,但不工作,不旋转箭头图像!

ParentViewHolder码:

代码语言:javascript
代码运行次数:0
复制
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);
    }
}

在库中称为展开和折叠:

代码语言:javascript
代码运行次数:0
复制
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() {}

}

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-26 17:16:24

TL;博士,您必须使用startAnimation()来表示ImageView,而不是setAnimation()

void setAnimation (Animation animation) 设置要为此视图播放的下一个动画。如果您想要动画立即播放,请使用startAnimation(android.view.animation.Animation)代替.

(引用自developer.android.com/reference/android/view/View.html

票数 2
EN

Stack Overflow用户

发布于 2020-11-29 07:14:28

代码语言:javascript
代码运行次数:0
复制
@Override
public void expand() {
    arrow_icn.setRotation(180);
}

@Override
public void collapse() {
    arrow_icn.setRotation(0);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45332523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档