我想在加载活动后滚动到RecyclerView列表的底部.
GENERIC_MESSAGE_LIST = (ArrayList) intent.getExtras().getParcelableArrayList(ConversationsAdapter.EXTRA_MESSAGE);
conversationView = (RecyclerView) findViewById(R.id.list_messages);
conversationView.setHasFixedSize(true);
conversationViewLayoutManager = new LinearLayoutManager(this);
conversationView.setLayoutManager(conversationViewLayoutManager);
conversationViewAdapter = new ConversationAdapter(GENERIC_MESSAGE_LIST, this);
conversationView.setAdapter(conversationViewAdapter);
Run Code Online (Sandbox Code Playgroud)
conversationView.scrollTo(...)
抛出了一个关于在RecyclerView中不受支持的例外,并且conversationView.scrollToPosition(...)
似乎没有做任何事情.
在上面的代码块之后,我补充道
conversationView.scrollToPosition(GENERIC_MESSAGE_LIST.size() + 1)
Run Code Online (Sandbox Code Playgroud)
这不起作用.有30个元素GENERIC_MESSAGE_LIST
.
我使用Recyclerview替换列表视图我想保持Recyclerview始终滚动到底部.
ListView可以使用此方法 setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL)
RecyclerView我用的方法 smoothScrollToPosition(myAdapter.getItemCount() - 1)
但是当软键盘弹出时,它取代了RecyclerView的内容.
我遵循了recyclerview指南并为我正在制作的应用程序构建了一个,但由于某种原因它不会滚动到底部.我将它与谷歌代码片段以及其他在线代码片段进行了比较,看不出差异.我发布了一张图片和我正在使用的代码.我正在使用制表符,因此recyclerview填充在片段中.
该应用程序的外观如下:
适配器类:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<Group> groups;
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView groupName;
public TextView groupDate;
public TextView groupLocation;
public …
Run Code Online (Sandbox Code Playgroud) android android-fragments android-recyclerview recyclerview-layout