- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个带有水平线性布局管理器的 RecyclerView,声明如下:
RecyclerView graph = (RecyclerView) findViewById(R.id.graph);
RecyclerView.LayoutManager classManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
graph.setLayoutManager(classManager);
graph.addItemDecoration(new ComponentDecorator(this)); //Just sets a margin around each item
我有一个方法可以像这样将占位符 View 插入到 RecyclerView 中:
private void insertPlaceholder(int index) {
int placeholderIndex = getIndexOfPlaceholder(); //returns index of existing placeholder, -1 if none
//No need to do anything
if(placeholderIndex == index)
return;
if(placeholderIndex == -1) {
ClassGraphItem placeholder = new ClassGraphItem();
placeholder.setType(ClassGraphItem.PLACEHOLDER);
mItems.add(index, placeholder);
Print.log("notify item inserted at index", index);
notifyItemInserted(index);
}
else {
ClassGraphItem placeholder = mItems.get(placeholderIndex);
mItems.remove(placeholderIndex);
mItems.add(index, placeholder);
notifyItemMoved(placeholderIndex, index);
}
}
占位符只是一个不可见的 View ,它模拟两个现有 View 之间的空间开口:
private class PlaceholderViewHolder extends RecyclerView.ViewHolder {
public PlaceholderViewHolder(View itemView) {
super(itemView);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(mComponentWidth, 1);
itemView.setLayoutParams(params);
itemView.setVisibility(View.INVISIBLE);
}
}
当插入的索引 > 0 时,它完美地工作。但是在索引 0 处,插入占位符或将现有占位符移动到 0 索引都不起作用,特别是 RecyclerView 不会动画显示在索引 0 处插入的新项目。如果我使用 notifyDataSetChanged()
它确实有效。然而,这并没有动画,也不是我正在寻找的效果。这对我来说似乎是一个错误,但我想确保没有其他原因导致此问题。
我使用的是最新版本的 recyclerview 支持库 (24.2.1)。谢谢!
最佳答案
我删除了 recycler.setHasFixedSize(true);
现在它可以工作了。我不知道为什么这会相关。
关于Android RecyclerView 适配器 : notifyItemInserted and notifyItemMoved at index 0 not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39683237/
为什么 notifyItemMoved 不重新绑定(bind)(我的意思是 onBindViewHolder 不是调用)我的 recyclerView 适配器?在顶部或底部移动项目后,我在点击时获得旧
我已经解决这个问题很多天了,看不到尽头,所以任何帮助都将不胜感激!这是问题所在: 我有一个房间数据库和一个回收站 View ,我在其中显示了该数据库的一部分。通常一切正常。但是,如果我尝试拖动(从而切
当前,我在 recyclerview 中执行拖放项目时遇到问题。 我正在引用 https://github.com/iPaulPro/Android-ItemTouchHelper-Demo 但是当在
我们的应用程序中有此功能,我们可以在其中上下拖动回收器 View 项目。 在 ItemTouchHelper.Callback() 的 onMove() 中我们调用 adapter.onItemMov
在我的应用程序中,我有一个使用 RecyclerView 实现的项目列表。在某些情况下,项目可能会移到列表的最后,我需要将其设置为动画。因此,首先我将项目移动到数据源(在本例中为 ArrayList)
我在使用 notifyItemMoved() 方法时遇到问题。它似乎错误地显示了未移动的 View 。 我的列表中有 4 个元素。我想要做的是为第 1 项和第 3 项之间的交换设置动画。第 1 项和第
我有一个由 LinearlayoutManager 管理的 RecyclerView,如果我将项目 1 与 0 交换,然后调用 mAdapter.notifyItemMoved(0,1),移动动画导致
我有一个带有水平线性布局管理器的 RecyclerView,声明如下: RecyclerView graph = (RecyclerView) findViewById(R.id.graph); Re
我是一名优秀的程序员,十分优秀!