use*_*538 7 animation android android-viewholder android-recyclerview
我想给a textView
内部的动画,recyclerView
以便在调用时向上过渡notifyItemChanged(position)
。这是我的onBindViewholder()
,当适配器发生更改时,它会自动被调用:
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
if (unfoldedIndexes.contains(position)) { // if already unfolded
bindUnfoldedState(holder, holder.getLayoutPosition());
}else{ // show the folded state}
}
public void bindUnfoldedState(ViewHolder holder, int position){
if(lc.isBtnEnabled()){
holder.Price.setText("text");
holder.Price.animate().alpha(1.0f).setDuration(500);
holder.Price.animate().translationY(-38).setDuration(500);
holder.checkText.animate().translationY(38).setDuration(500);
}else {
holder.Price.animate().alpha(0.0f).setDuration(500);
holder.Price.animate().translationY(0).setDuration(500);
holder.checkText.animate().translationY(0).setDuration(500);
}
}
Run Code Online (Sandbox Code Playgroud)
我notifyItemChanged()
被这样称呼fragment
onClick
:
ok.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
// some changes to the data
adapter.getLcns().get(Position).setBtnEnabled(true);
adapter.notifyItemChanged(Position);
}
}
Run Code Online (Sandbox Code Playgroud)
isBtnEnabled()
如果etBtnEnabled(true)
调用s 为true 。
问题是动画没有发生。使用日志,我可以确认onBindViewHolder()
正在调用该动画,并且应该出现动画但没有发生。
listView
在转换为a之前,我使用了recyclerView
正常模式,并且动画正在制作中getView()
用于Adapter.notifyItemChanged(position, payload)
将更新部署到已经可见的 ViewHolder:
单击时:
ok.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
// some changes to the data
adapter.getLcns().get(Position).setBtnEnabled(true);
adapter.notifyItemChanged(Position, true); // "true" is the payload
}
}
Run Code Online (Sandbox Code Playgroud)
适配器:
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position, List<Object> payloads) {
if(payloads != null && !payloads.isEmpty()){ // update payloads, partial rebind
Object lastPayload = payloads.get(payloads.size -1)); // in this case only last payload is meaningful
if(lastPayload instanceof Boolean)
bindUnfoldedState(holder, lastPayload);
}else
onBindViewHolder(holder, position); // regular binding of item
}
public void bindUnfoldedState(ViewHolder holder, boolean unfold){
if(unfold){ ... }
else { ... }
}
// you should also consider adding this override to prevent animation leaking when viewholder
// is recycled and reused for another position:
@Override
public void onViewRecycled(ViewHolder holder){
holder.Price.animate().cancel();
holder.checkText.animate().cancel();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
161 次 |
最近记录: |