2013-05-04 51 views
0

的有沒有關於它的很多問題上SOF:如何獲得FPS我的ListView

Android - How can I measure performance of ListView and other Views?

有一個解決方案使用Hierarchy Viewer。但我只想在ListView上獲得FPS

而且該層次結構查看器DOC狀態:

層次瀏覽器只能連接到設備上運行的一個開發者版本 Android系統

的這臺沒有檢測到我的設備。我不知道開發者版本是什麼。

我讀的地方仿真器是一種開發版本,但它們可能不準確

另外,我發現這個在我的日誌貓,當我滾動ListView

11月5日至四日:14:24.697:I/SurfaceTextureClient(20849):STC :: queueBuffer] (這一點:0x5e74b878)FPS:0.39,杜爾:17832.35,最高:17194.94,最低:17.54

是那個FPS與我的ListView?

因爲它從0.3 to 60.1

各不相同,據我所知60是你最大。

回答

1

你需要繼承一個ListView並覆蓋其的onDraw(),這裏是一個示例代碼,應該相當多的工作開箱:

public class FPSListView extends ListView 
{ 
    private Toast fpsToast; 
    private long currentTime; 
    private long prevTime; 

    public FPSListView(Context context){ 
     super(context); 
     fpsToast = Toast.makeText(context, "", Toast.LENGTH_SHORT); 
    } 

    public FPSListView(Context context, AttributeSet attrs){ 
     super(context, attrs); 
     fpsToast = Toast.makeText(context, "", Toast.LENGTH_SHORT); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) {   
     super.onDraw(canvas); 

     currentTime = SystemClock.currentThreadTimeMillis(); 
     long deltaTime = currentTime - prevTime; 
     long fps = 1000/deltaTime; 
     fpsToast.setText("FPS: " + fps); 
     fpsToast.show(); 
     prevTime = currentTime; 
    } 
}