英文:
How to convert "apply" in this kotlin code to java?
问题
我需要将这段 Kotlin 代码转换为 Java,以便为 RecyclerView 设置 itemAnimator:
cardStackView.getItemAnimator().setSupportsChangeAnimations(false);
目前,我已经想到了以下类似的代码:
cardStackView.setItemAnimator(new DefaultItemAnimator() {
@Override
public void setSupportsChangeAnimations(boolean supportsChangeAnimations) {
super.setSupportsChangeAnimations(supportsChangeAnimations);
}
});
英文:
I need to convert this kotlin code to java to set the itemAnimator for a recylcer view
cardStackView.itemAnimator.apply {
if (this is DefaultItemAnimator) {
supportsChangeAnimations = false
}
}
So far i have come up with something like this:
cardStackView.setItemAnimator(new DefaultItemAnimator(){
@Override
public void setSupportsChangeAnimations(boolean supportsChangeAnimations) {
super.setSupportsChangeAnimations(supportsChangeAnimations);
}
}
);
答案1
得分: 2
RecyclerView.ItemAnimator itemAnimator = cardStackView.getItemAnimator();
if (itemAnimator instanceof DefaultItemAnimator) {
DefaultItemAnimator di = (DefaultItemAnimator) itemAnimator;
di.setSupportsChangeAnimations(false);
}
英文:
RecyclerView.ItemAnimator itemAnimator = cardStackView.getItemAnimator();
if (itemAnimator instanceof DefaultItemAnimator) {
DefaultItemAnimator di = (DefaultItemAnimator) itemAnimator;
di.setSupportsChangeAnimations(false);
}
专注分享java语言的经验与见解,让所有开发者获益!
评论