2016-09-18 61 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);