因此,我有一个recyclerview,该视图显示从Firebase数据库获取的列表。但是,每次添加新项目时,recyclerview都会向上滚动,没有明显的原因。我该如何解决?我遍历了stackoverflow上的所有解决方案,并试图实现它们,但徒劳无功。
我已禁用了动画,但这种情况仍然存在。
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_artcall_feed);
setupBottomNavigationView();
Artcall_feed_list = (RecyclerView)findViewById(R.id.artcall_feed);
mFeedRef = FirebaseDatabase.getInstance().getReference().child("Artcall_Feed").child("general");
mtoolbar = findViewById(R.id.genpage_toolbar);
setSupportActionBar(mtoolbar);
Artcall_feed_list.setLayoutManager(new LinearLayoutManager(this));
Artcall_feed_list.getItemAnimator().setChangeDuration(0);
//Artcall_feed_list.setNestedScrollingEnabled(false);
RecyclerView.ItemAnimator animator = Artcall_feed_list.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
}
@Override
protected void onStart() {
super.onStart();
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (currentUser == null) {
sendtoStart();
}
else {
FirebaseRecyclerAdapter<Feed_list, FundedArtcalls> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Feed_list, FundedArtcalls>(
Feed_list.class,
R.layout.single_artcall_feed_layout,
ArtcallFeedActivity.FundedArtcalls.class,
mFeedRef
) {
@Override
protected void populateViewHolder(final FundedArtcalls viewHolder, final Feed_list model, final int position) {
final String feed_item_id = getRef(position).getKey();
viewHolder.setArtist_name(model.getArtist_name());
viewHolder.setPerf_location(model.getPerf_location());
new_percent = model.getPercent_funded();
viewHolder.setPercent_funded(new_percent, old_percent);
viewHolder.setCurrent_like_count(model.getCurrent_like_count());
viewHolder.setTarget_like_count(model.getTarget_like_count());
viewHolder.setLikeStatus(feed_item_id);
viewHolder.setImage_url(model.getImage_url());
}
};
Artcall_feed_list.setAdapter(firebaseRecyclerAdapter);
RecyclerView.ItemAnimator animator = Artcall_feed_list.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
}
}
答案 0 :(得分:0)
删除此行“ Artcall_feed_list.getItemAnimator()。SetChangeDuration(0);”