2014-09-04 3 views
0

터치 및 제스처 감지 API를 사용하는 대신 모든 터치를 직접 처리하는 응용 프로그램이 있습니다. 부동 창이고 작동하는 유일한 방법이기 때문입니다.onTouch의 android setBackgroundColor가 작동하지 않는 경우가 있습니다.

내가하는 일 중 하나는 손가락 아래에서보기의 색상을 변경하는 것입니다.

myView.setBackgroundColor(getResources().getColor(R.color.white)); 

나는 현재 옆에있는보기로 이동하고 매우 빠르게 돌아올 때 그것은 작동하지 않습니다 OnTouch 나는이 다른 경우 이전의 내가 실행에서 손가락 아래에있는보기 확인.

로그로 확인했는데 발견 된보기가 정확합니다. 그리고 또한 체크하고 setBackgroundColor가있는 행이 실행됩니다.

그래서 무엇을해야할지 모르겠습니다. setBackgroundColor가 작동하지 않는 경우가 있습니까? onTouch가 실행하는 데 너무 많은 시간이 걸리면 작업이 완료되지 않습니까?

해결 방법에 대한 단서가 있습니까?

편집 : 현재보기 옆에 가서 빨리 돌아올 때만 오류가 발생합니다. 코드를 추가하지 않은 이유는 내가 추상화 한 것보다 읽기가 더 힘들다고 생각했기 때문입니다. 나는 그것을 정리하고 게시했다. 호출 된 메소드가 관련 있다고 생각되면 추가 할 수 있습니다. EDIT 2 : ACTION이 ACTION_DOWN 또는 ACTION_UP이 아닌 경우 실행되는 코드. 그러한 경우는 관련이 없습니다.

if ((isPortrait && isPortraitMeasured) || (!isPortrait && isLandscapeMeasured)) { 
    //Log.d("algor", "Here calculate where it is"); 
    final int lastCol = currentColumn; 
    final int lastRow = currentRow; 
    findCell((int) event.getRawX(), (int) event.getRawY()); 

    if ((lastCol == currentColumn && lastRow == currentRow)) { 
     if (isPortrait && currentRow==-1 || (!isPortrait && currentColumn==-1) 
       && !wasPressed && currentTable!=mainTable) { 
      //is actionBar. Check if finger is over back icon, to go back 

      //Code not related to the problem... 
     } 

    } else { 

     int currentIndex = getAppsListIndex(); 
     if (currentIndex >= 0) { 

      View nextApp; 

      if (isPortrait) 
       nextApp = cellsP.get(currentTable).get(currentIndex); 
      else 
       nextApp = cellsL.get(currentTable).get(currentIndex); 
      final Object tag = nextApp.getTag(); 

      if (tag instanceof FolderData) { 

       //Code not related to the problem... 

      } else { 
       Log.d("fastf", "time to change color"); 
       //nextApp.setBackgroundColor(getResources().getColor(R.color.white)); 
       nextApp.setBackgroundColor(whiteColor); 
       //nextApp.setBackground(getResources().getDrawable(R.color.white)); 
       /*final View app = nextApp; 
       app.post(new Runnable() { 
        @Override 
        public void run() { 
         app.setBackgroundColor(getResources().getColor(R.color.white)); 
        } 
       });*/ 

      } 

     } else { 

      //Code not related to the problem... 

     } 

     int lastIndex = getAppsIndexFromInts(lastRow, lastCol); 
     //lastCol != -2 is because otherwise, on opening the launcher it animates 
     // the last app launched 
     if (lastIndex >= 0 && lastCol != -2) { 
      View lastApp; 
      if (isPortrait) 
       lastApp = cellsP.get(currentTable).get(lastIndex); 
      else 
       lastApp = cellsL.get(currentTable).get(lastIndex); 


      ObjectAnimator animator = ObjectAnimator.ofInt(lastApp, 
        "backgroundColor", getResources().getColor(R.color.clear_gray), 
        getResources().getColor(R.color.white_overlay_transition)); 
      animator.setDuration(500); 
      animator.setEvaluator(new ArgbEvaluator()); 
      animator.start(); 
     } 
    } 

} 
+0

getResources(). getColor는이 값을 오래 걸리며 캐시합니다. – pskink

+0

오래 걸리지 않았습니다. 나는 그것을 캐쉬했다. – lotdrops

+0

어디에서 myView.setBackgroundColo를 호출합니까? – pskink

답변

0

그것을 시도

myView.setBackground (의 GetResources() getDrawable (R.color.white).);

+0

setBackgroundColor (...)와 같은 결과 – lotdrops

+0

전체 코드를 작성하여 문제를 찾을 수 있습니다. – user3798394

0
myView.setBackgroundColor(getResources().getColor(R.color.bgcolor)); 

당신은

nextApp.setBackgroundResource (...) 대신에 다른 사람을 사용해야합니다

<color name="bgcolor">#ffffff</color> 
+0

다른 리소스 이름으로 가지고있는 것과 똑같습니다. 그게 어떻게 바뀌는거야? – lotdrops

+0

xml 파일에서 색상을 상속받을 수 있습니다. 당신은 쇼 링크에서 내 대답을 볼 수 있습니다. http://stackoverflow.com/questions/25640075/how-to-inherit-style-in-layout-in-android/25642037#25642037 –

1

color.xml.

당신의 "R.color.white"때문에 자원입니다.

좋은 하루 보내십시오.

낡은 질문 이었지만 동일한 문제에 직면하여이 변경 사항을 해결했습니다.

관련 문제