8
我創建了一個非常基本的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);
}
}
}
}
現在,當我滾動超出了第一項,滾動條跳回到頂部,然後繼續正常進行。第二個問題是當我滾動到底部時,滾動條停止提前。這是支持庫還是我自己的錯誤?
有同樣的問題。 – EyesClear 2014-11-08 23:29:49
它似乎是一個錯誤:https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=scrollbar&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort= &id = 78545 – Kuno 2014-11-09 00:54:45
嘗試使用v7 recyclerview庫https://developer.android.com/tools/support-library/features.html#v7並查看是否得到相同的錯誤。考慮到這不是最終版本,Android團隊表示還有一些事情他們仍需要解決。 – vovahost 2014-11-09 00:55:25