作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序中,我想要展开和折叠 recyclerView
!
我可以展开和折叠 recyclerView
,为此我使用了这个 library:https://github.com/thoughtbot/expandable-recycler-view
我想要在点击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() {}
}
如何解决此问题并在单击 recyclerView
(展开 或 折叠)时旋转箭头图像???
最佳答案
TL;DR 您必须为 ImageView
使用 startAnimation()
而不是 setAnimation()
。
void setAnimation (Animation animation)
Sets the next animation to play for this view. If you want the animation to play immediately, use startAnimation(android.view.animation.Animation) instead [...]
关于android - 如何在Android中展开recyclerView时旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45332523/
我是一名优秀的程序员,十分优秀!