2016-09-18 57 views
0

如何在收到新数据时保持RecyclerView中“滚动条”的位置?例如,Whatsapp?Android如何初始化活动RecyclerView Scrollbars INVERTED to BOTTOM?

<android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerViewchatView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerInParent="true" 
     android:scrollbars="vertical" 
     android:layout_above="@+id/botaoenviar"/> 


    protected void onCreate(Bundle savedInstanceState) {... 
    recyclerView.smoothScrollToPosition(recyclerView.getAdapter().getItemCount() -1); 
    final Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      getDataUsuarioDestino(); 
      //adapter.notifyDataSetChanged(); 
      handler.postDelayed(this, 3000); 
     } 
    }, 3000); 

回答

0

[解决]

该解决方案是创建recyclerview适配器尺寸的计数,并且在的scrollPosition manualy设置

int recyclerposition = recyclerView.getAdapter().getItemCount(); 
     recyclerView.scrollToPosition(recyclerposition-1);