每当添加新项目时,RecyclerView都会不断向上滚动.如何解决这个问题?



因此,我有一个回收器视图,其中显示了从我的Firebase数据库中获取的列表。但是,每次添加新项目时,回收器视图都会无缘无故地向上滚动。我该如何解决这个问题?我已经浏览了堆栈溢出上的所有解决方案,并尝试实现它们,但徒劳无功。

我已经禁用了动画,但这仍然存在。

我的代码:

@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);
}
}
}

删除此行"Artcall_feed_list.getItemAnimator ((。设置更改持续时间 (0(;">

相关内容

  • 没有找到相关文章

最新更新