마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

애니메이션이 심하게 버벅거립니다.

0 추천

버튼을 누르면 

http요청후 받은 response를 파싱해 3개의 이미지 뷰가 움직이는 스레드입니다. 

핸들러에 인자로 보내는 runnable 을 보시면 3개의 이미지뷰를 위한 애니매이션이 있는데

주석처리 하고 살펴보니 1개의 애니메이션은 괜챃았으나 

2개 이상애니메이션을 실행하면 심하게 버벅이기 시작합니다.

문제가 있는 코드인가요?

protected String doInBackground(String... params) {
    while (runnig){
        HttpUrl url = new HttpUrl.Builder()
                .scheme("http") //http
                .host("xxx")
                .port(3000)                
                .build();

        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .build();

        try {
            Response response = client.newCall(request).execute();
            responseStr = response.body().string();
            JSONArray jsonOutput = null;
            try {
                jsonOutput = new JSONArray(responseStr);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            JSONObject tem = jsonOutput.getJSONObject(0);
            temStr = tem.getString("tem");
            speedStr = tem.getString("speed");
            rpmStr = tem.getString("rpm");
            valtageStr = tem.getString("valtage");
            airflowStr = tem.getString("airflow");
            timeStr = tem.getString("lastTime");

        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        handler.post(new Runnable() {
            @Override
            public void run() {  // Runnable 의 Run() 메소드에서 UI 접근
                PID1.setText("Vatage: " +valtageStr);
                PID2.setText("Temperature : "+temStr);
                PID3.setText("Speed : "+speedStr);
                PID4.setText("Rpm : "+rpmStr);
                PID5.setText("Airflow : "+airflowStr);
                if(valtageStr!=null && airflowStr != null) {
                    progressBarValtage.setPos(Integer.parseInt(valtageStr));
                    progressBarAirflow.setPos(Integer.parseInt(airflowStr));
                }
                int rpmint = Integer.parseInt(rpmStr);
                rpmint = rpmint*2;
                RotateAnimation ani1 = new RotateAnimation(beforeDgreeRpm,rpmint,RotateAnimation.RELATIVE_TO_SELF,0.85f,RotateAnimation.RELATIVE_TO_SELF,0.3f);
                ani1.setFillAfter(true);
                ani1.setDuration(1000);
                ani1.setRepeatCount(0);
                rpmView.setAnimation(ani1);
                rpmView.startAnimation(ani1);
                beforeDgreeRpm = rpmint;

                //Tem은 50~100의 값이 들어온다
                int temint = Integer.parseInt(temStr);
                temint = temint/2;
                RotateAnimation ani2 = new RotateAnimation(beforeDgreeTem,temint,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.85f);
                ani2.setFillAfter(true);
                ani2.setDuration(1000);
                ani2.setRepeatCount(0);
                temView.setAnimation(ani2);
                temView.startAnimation(ani2);
                beforeDgreeTem = temint;

                //speed는 20~80이 들어온다
                int speedint = Integer.parseInt(speedStr);
                speedint = speedint*2;
                RotateAnimation ani3 = new RotateAnimation(beforeDgreeSpeed,speedint,RotateAnimation.RELATIVE_TO_SELF,0.85f,RotateAnimation.RELATIVE_TO_SELF,0.3f);
                ani3.setFillAfter(true);
                ani3.setDuration(1000);
                ani3.setRepeatCount(0);
                speedView.setAnimation(ani3);
                speedView.startAnimation(ani3);
                beforeDgreeSpeed = speedint;
            }
        });
        if(isCancelled()){runnig=false;}
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    return null;
}

 

 

 

신입 (570 포인트) 님이 2016년 12월 2일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...