2014-03-12 3 views
1

ViewPager를 스 와이프하고자합니다. 페이지 스 와이프에 다음 코드를 사용했습니다. 그러나 불행히도 작동하지 않습니다.Android Robotium - ViewPager 스 와이프가 작동하지 않습니다.

Solo solo = new Solo(getInstrumentation(), getActivity());  
      int screenHeight = activityUtils.getCurrentActivity().getWindowManager().getDefaultDisplay() 
        .getHeight(); 
      int screenWidth = activityUtils.getCurrentActivity(false).getWindowManager().getDefaultDisplay() 
        .getWidth(); 
      float x = screenWidth/3.0f * 2.0f; 
      float y = screenHeight/3.0f * 2.0f; 

시도 : 1

solo.swipe(x, 0, y, y, 40); 

시도 : 2

if (side == Side.LEFT) 
    drag(0, x, y, y, 40); 
else if (side == Side.RIGHT) 
    drag(x, 0, y, y, 40); 

시도 : 3 다음 방법 작동하지만, 그것은 단지 하나의 페이지를 움직이는하고 또한 움직이는 매우 느리게.

solo1.scrollToSide(Solo.RIGHT); 

빠른 스 와이프 옵션이 있습니까? 어느 것이 가장 좋습니까? 친절하게 당신의 아이디어를 공유하십시오.

Robotium 나의 코드가 5.1보기 호출기에 대한

for (int count = 0; count < noOfPages; count++) 
    solo.swipeToRight(count); 

방법이

private void swipeToLeft(int stepCount) { 
    Display display = solo.getCurrentActivity().getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth(); 
    int height = display.getHeight(); 
    float xStart = width - 10 ; 
    float xEnd = 10; 
    solo.drag(xStart, xEnd, height/2, height/2, stepCount); 
} 

private void swipeToRight(int stepCount) { 
    Display display = solo.getCurrentActivity().getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth(); 
    int height = display.getHeight(); 
    float xStart = 10 ; 
    float xEnd = width - 10; 
    solo.drag(xStart, xEnd, height/2, height/2, stepCount); 
} 

답변

1

이 문제는 Robotium 5.1에서 수정되었습니다. 당신은 여기에서 다운로드 할 수 있습니다 :

https://code.google.com/p/robotium/wiki/Downloads?tm=2

+0

Robotium 5.1을 다운로드했지만 여전히 문제가 있습니다. – vinoth

+0

이것을 사용해보십시오 : solo.scrollViewToSide (solo.getView ("viewPager"), Solo.RIGHT); – Renas

0

을지나 가게한다 음 옆으로 스크롤에 대한 robotium의 환매 특약의 코드는 다음과 같습니다

public void scrollToSide(int side) { 
     switch (side){ 
     case RIGHT: scroller.scrollToSide(Scroller.Side.RIGHT, 0.70F); break; 
     case LEFT: scroller.scrollToSide(Scroller.Side.LEFT, 0.70F); break; 
     } 
    } 



@SuppressWarnings("deprecation") 
    public void scrollToSide(Side side, float scrollPosition) { 
     int screenHeight = activityUtils.getCurrentActivity().getWindowManager().getDefaultDisplay() 
       .getHeight(); 
     int screenWidth = activityUtils.getCurrentActivity(false).getWindowManager().getDefaultDisplay() 
       .getWidth(); 
     float x = screenWidth * scrollPosition; 
     float y = screenHeight/2.0f; 
     if (side == Side.LEFT) 
      drag(0, x, y, y, 40); 
     else if (side == Side.RIGHT) 
      drag(x, 0, y, y, 40); 
    } 

public void drag(float fromX, float toX, float fromY, float toY, 
     int stepCount) { 
    dialogUtils.hideSoftKeyboard(null, false, true); 
    scroller.drag(fromX, toX, fromY, toY, stepCount); 
} 

그래서 당신 같은 oks가 가까이 있어야합니다, 제 추측은 드래그 호출에서 사용한 번호입니다. 호출기 작업을 수행 할 수 없습니다. 나는 당신이 바꾸는 경우에이 숫자가 스 와이프를 완료하는 데 필요한 이벤트의 총량이기 때문에 빠르게 스 와이프를해야한다는 마지막 매개 변수를 제외하고는 로보 티움에 의해 사용 된 열거자를 시도해 볼 것을 제안합니다. 번호를 시험해야 할 수도 있습니다.

4

solo.scrollToSide (Solo.RIGHT); 이 구현도 충분히 빠릅니다.