2012-10-11 96 views
3

即時通訊使用RealViewSwitcher輕掃視圖,這沒關係,我的問題類似於this之一。我將嘗試通過這張圖解釋我的場景scenarioAndroid:RealViewSwitcher不垂直滾動

listview < ------>詳細視圖------>滑動視圖(水平)。 詳細視圖只顯示部分內容,如果嘗試滾動則什麼都不會發生。

詳細布局(無垂直滾動)

<?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> 

佈局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> 

回答

0

我面臨着同樣的問題,並通過在RealViewSwitcher攔截觸摸事件找到解決方案。

編輯:以前發佈的變體不適用於較新的API。有代碼的第三次修訂。

添加這些行到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:還需要編輯onTouchEvent方法和替換case MotionEvent.ACTION_DOWN:體,如下所示:

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;