2014-04-15 39 views
0

我想在Android消息傳遞/聊天應用程序中使用ListView,並且想在添加項目時順利進行動畫設置(但只有當用戶正在查看最新的消息,如果他們正在查看以前的消息,我不需要動畫)。Android ListView transcriptMode =「正常」添加項目時平滑動畫

我正在使用stackFromBottom =「true」和transcriptMode =「normal」,這讓我接近滾動到最新消息時的行爲,如果用戶正在查看最新消息,已經滾動到之前的消息。它似乎像transcriptMode =「正常」或「alwaysScroll」的行爲很快滾動到新消息。我希望有一些方法可以讓這個滾動過程在1秒內動畫化。

<?xml version="1.0" encoding="utf-8"?> 

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:stackFromBottom="true" 
    android:transcriptMode="normal"/> 

回答

2

設置

android:transcriptMode = "disabled"

,而使用

int lastIndex = listView.getChildCout() - 1; 
listView.smoothScrollToPosition(lastIndex); 

每次你添加一個新的項目。

+0

錯字:'getChildCout()'應該是'getChildCount()' – axelbrz