首页 文章

ObjectAnimator:如何检测帧率?

提问于
浏览
2

我在不同设备上使用ObjectAnimator和测试应用程序 . 在一些旧的慢速手机上它动画太糟糕了(没有GPU,没有内存等),所以我想自动将用户切换到应用程序的第二版(精简版) .

那么如何快速检测出ObjectAnimator是什么?

  • 是否有一些帧率报告?我一无所获 .

  • 编舞有相同的听众吗?它列出了catlog中的错误,但我想在代码中获取它 .

01-22 05:55:15.775: INFO/Choreographer(3794): Skipped 33 frames! The application may be doing too much work on its main thread.

注意:我知道如何通过system命令解析catlog,但在我看来它不是一个聪明或快速的解决方案 .

注2:我不需要加快速度 . 我需要检测慢速手机 .

1 回答

  • 0

    好的,这个解决方案运行正常

    它可以从ObjAnimator的循环中调用(例如,监听器 - onRepeat)

    您可以统计事件并对设备速度做出结论 .

    附:它不是聪明的,但直到没有人回答关于本机帧率报告...

    boolean getCatLog(){
        boolean yes=false;
        try {
            Process process = Runtime.getRuntime().exec("logcat -d");
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String output;
            String lastLine = null;
            while ((output = reader.readLine()) != null) {
                lastLine = output;
            }
            if(lastLine!=null && lastLine.contains("Choreographer")){
                Log.d(TAG,"yes!");  //do not remove!
                yes=true;
            }
            reader.close();
            process.waitFor();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return yes;
    }
    

相关问题