检查生成的ListView时间

时间:2014-03-10 10:04:29

标签: android performance listview android-adapter

我想知道如何跟踪绘制/填充列表视图所花费的时间。我正在使用List的自定义数组适配器。我在考虑使用System.nanoTime()

我尝试使用以下代码:

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    long startNano = System.nanoTime();
    View view = inflater.inflate(R.layout.trip_listview, container, false);
    ListView lv = (ListView) view.findViewById(android.R.id.list);
    TripsArrayAdapter tripsArrayAdapter = new TripsArrayAdapter(getActivity(), CachedData.getInstance().getTripsList());
    lv.setAdapter(tripsArrayAdapter);
    long endNano= System.nanoTime();
    System.out.println("Time create: "+(endNano-startNano));
    return view;
}

这是正确的方法吗?

1 个答案:

答案 0 :(得分:0)

我不会依赖上面的代码,因为在setAdapter方法中没有完成绘图。我要做的是使用HierarchyViewer并检查每个视图绘制和布局的时间。

开发者网站上有一篇很棒的文章debugging UI,来自Romain Guy的another article处理了UI效果。