2011-08-22 2 views
1

현재 각 항목이 표시 크기와 일치하는 갤러리가 있습니다. 사용자가 뷰를 어느쪽으로 든 던지려고 할 때, 자동 스크롤 대신에 바로 다음보기로 가고 싶습니다.갤러리에서 제스처로보기를 하나만 탐색하십시오.

어떻게하면됩니까?

+0

나는'Gallery'를 덤프하고'ImageView'를 사용하는 것과'GestureDetector'처럼 보인다 . 스 와이프 할 때'ImageView'를 업데이트하십시오. – CommonsWare

+0

내 사용자 정의보기에서 이미지 만 그리기 전에이 방법을 사용했습니다. 그러나 HTML5 지원을위한 WebView처럼 내부의 모든 유형의 내용을 추가 할 수 있도록 지원하는보기를 사용해야했습니다. –

+0

확인한 다음 'ViewFlipper'와 'GestureDetector'를 사용하십시오. 실제로, 나는 그것을하는'ViewSwiper'를 가지고 있습니다. https://github.com/commonsguy/cwac-viewswiper – CommonsWare

답변

1

이 스 니펫을 확인하십시오. 그것은 스크롤링 상수를 사용하지 않고 대신 scolling 키 이벤트를 사용하여 다른 해상도를 처리합니다.

private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){ 
    return e2.getX() > e1.getX(); 
} 

@Override 
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ 
    int kEvent; 
    if(isScrollingLeft(e1, e2)){ //Check if scrolling left 
     kEvent = KeyEvent.KEYCODE_DPAD_LEFT; 
    } 
    else{ //Otherwise scrolling right 
     kEvent = KeyEvent.KEYCODE_DPAD_RIGHT; 
    } 
    onKeyDown(kEvent, null); 
    return true; 
} 

이 코드 조각 갤러리를 확장하는 galleryView 모델에 속하며 레이아웃이

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="180dp"> 
    <com.example.android.GalleryView 
     android:id="@+id/gallery" 
     android:layout_width="fill_parent" 
     android:layout_height="180dp" 
     android:gravity="bottom" 
     android:fadingEdge="none"/> 
</LinearLayout> 
+0

완벽하게, 정말 고마워요! (채팅을 통해 계속이 토론) (http://chat.stackoverflow.com/rooms/2741/discussion-between-marcos-vasconcelos-and-commonsware)! –