2013-05-04 23 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; 
    } 
}