我想在回收站视图上启用投掷/快速滚动。我的意思是,如果用户执行甩动动作,视图会继续滚动并开始减速(我猜这称为快速滚动)。
我在 ScrollView 中有一个 RecyclerView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scroll">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/items"/>
</ScrollView>
我将布局管理器设置为线性
RecyclerView itemsView = findViewById(R.id.items);
stocksView.setLayoutManager(new LinearLayoutManager(this));
我确实有一个自定义适配器附加到 RecyclerView
public abstract class RecyclerAdapter<E>
extends RecyclerView.Adapter<ItemView>
{
private ItemTouchHelper touchHelper;
protected final List<E> items = new ArrayList<>();
protected RecyclerAdapter()
{
}
@Override
public void onBindViewHolder(@NonNull final ItemView holder, int position)
{
}
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView)
{
super.onAttachedToRecyclerView(recyclerView);
touchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(this));
touchHelper.attachToRecyclerView(recyclerView);
}
@Override
public int getItemCount()
{
return items.size();
}
}
我的 ItemTouchHelperCallback 是
public class ItemTouchHelperCallback
extends ItemTouchHelper.Callback
{
ItemTouchHelperCallback(RecyclerAdapter adapter)
{
}
@Override
public boolean isItemViewSwipeEnabled()
{
return true;
}
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)
{
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
int swipeFlags = 0;
return ItemTouchHelper.Callback.makeMovementFlags(dragFlags, swipeFlags);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target)
{
if (source.getItemViewType() != target.getItemViewType())
{
return false;
}
return true;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int i)
{
}
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState)
{
// We only want the active item to change
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE)
{
// Let the view holder know that this item is being moved or dragged
((ItemView) viewHolder).onItemSelected();
}
super.onSelectedChanged(viewHolder, actionState);
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder)
{
super.clearView(recyclerView, viewHolder);
// Tell the view holder it's time to restore the idle state\
((ItemView) viewHolder).onItemClear();
}
}
然而不知何故,每当我尝试滚动它时,我抬起手指的那一秒就停止了。我如何让它继续尝试滚动。