2012-10-11 4 views
3

Im en utilisant RealViewSwitcher pour faire glisser la vue et c'est ok, mon problème est similaire à celui de this. Je vais essayer d'expliquer un peu mon scénario par cette image scenarioAndroid: RealViewSwitcher ne défile pas en vertical

listview < ------> vue de détail ------> vue de balayage (horizontal). La vue de détail ne montre que partiellement et si essayer de faire défiler rien ne se passe.

mise en page de détail (pas de défilement vertical)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:textColorHint="#FF0000" 
     android:textSize="12dp" 
     android:textStyle="bold" 
     android:typeface="sans" /> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="150dip" 
      android:layout_height="120dip" 
      android:scaleType="centerCrop" 
      android:src="@drawable/stub"/> 
    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:padding="20dip" 
     android:textColor="#999999" 
     android:textColorLink="#ff0000" 
     android:textSize="20dip" 
     android:textStyle="normal" 
     android:typeface="sans" /> 
</LinearLayout> 

de mise en page avec RealViewSwitcher

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:orientation="vertical"> 

    <it.application.ppn.lib.RealViewSwitcher 
     android:id="@+id/horizontal_pager" 
     android:layout_width="fill_parent" 
     android:layout_height="0px" 
     android:layout_weight="1"> 

    </it.application.ppn.lib.RealViewSwitcher> 

</LinearLayout> 

Répondre

0

Je face au même problème et a trouvé la solution en interceptant événement tactile dans RealViewSwitcher.

EDIT: La variante précédente affichée ne fonctionne pas avec les API récentes. Il y a une troisième révision du code.

Ajouter ces lignes dans la mise en œuvre RealViewSwitcher:

@Override 
public boolean onInterceptTouchEvent(MotionEvent event) { 

    // prevent vertical scrolling when view switching in progress 
    if (!mScroller.isFinished()) 
     return true; 

    switch (event.getAction()) { 
    case MotionEvent.ACTION_DOWN: 
     mScrollLocked = false; 
     mLastX = event.getX(); 
     mLastY = event.getY(); 
     mDeltaX = 0; 
     mDeltaY = 0; 
     onTouchEvent(event); 
     break; 

    case MotionEvent.ACTION_MOVE: 
     final float x = event.getX(); 
     final float y = event.getY(); 
     mDeltaX += Math.abs(x - mLastX); 
     mDeltaY += Math.abs(y - mLastY); 
     mLastX = x; 
     mLastY = y; 
     if (mDeltaX > mDeltaY) { 
      mScrollLocked = true; 
      onTouchEvent(event); 
     } else { 
      snapToDestination(); 
     } 
     break; 
    } 

    if (mScrollLocked) 
     return true; // prevent furhter processing 

    return super.onInterceptTouchEvent(event); 
} 

EDIT2: devez également modifier la méthode onTouchEvent et remplacer le corps case MotionEvent.ACTION_DOWN: comme suit:

case MotionEvent.ACTION_DOWN: 

     /* 
     * If being flinged and user touches, stop the fling. isFinished will be false if being flinged. 
     */ 
     mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING; 

     if (mTouchState == TOUCH_STATE_SCROLLING) { 
      mScroller.abortAnimation(); 
     } 

     // Remember where the motion event started 
     mLastMotionX = x; 

     break;