android – RecyclerView滚动条在第一个项目后跳回到顶部

我创建了一个非常基本的RecyclerView示例.

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MyActivity">

    <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"/>

</RelativeLayout>

活动:

public class MyActivity extends Activity {

    RecyclerView mRecyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mRecyclerView.setAdapter(new TestAdapter());
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    public static class TestAdapter extends RecyclerView.Adapter<TestAdapter.ViewHolder> {
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(android.R.layout.simple_list_item_1, viewGroup, false);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int i) {
            viewHolder.tv.setText("Row " + (i + 1));
        }

        @Override
        public int getItemCount() {
            return 30;
        }

        public static class ViewHolder extends RecyclerView.ViewHolder {

            TextView tv;

            public ViewHolder(View itemView) {
                super(itemView);
                tv = (TextView) itemView.findViewById(android.R.id.text1);
            }
        }
    }
}

现在,当我滚动到第一个项目之外时,滚动条会跳回到顶部然后继续正常.第二个问题是当我滚动到底部时,滚动条会提前停止.这是支持库中的错误还是我自己的错?

最佳答案
here所述,此错误已在新版本的支持库v21.0.2中得到修复.

转载注明原文:android – RecyclerView滚动条在第一个项目后跳回到顶部 - 代码日志