2015-04-17 88 views

回答

0

slidingPanel SlidingPaneLayout和尋呼機 ViewPager裏面我會告訴我的例子。 Firstable創建以下

public class SmartSlidingPane extends SlidingPaneLayout { 
 
    private float mInitialMotionX; 
 
    private float mInitialMotionY; 
 
    private float mEdgeSlop; 
 

 
    public SmartSlidingPane(Context context) { 
 
     this(context, null); 
 
    } 
 

 
    public SmartSlidingPane(Context context, AttributeSet attrs) { 
 
     this(context, attrs, 0); 
 
    } 
 

 
    public SmartSlidingPane(Context context, AttributeSet attrs, int defStyle) { 
 
     super(context, attrs, defStyle); 
 

 
     ViewConfiguration config = ViewConfiguration.get(context); 
 
     mEdgeSlop = config.getScaledEdgeSlop(); 
 
    } 
 

 
    @Override 
 
    public boolean onInterceptTouchEvent(MotionEvent ev) { 
 

 
     switch (MotionEventCompat.getActionMasked(ev)) { 
 
      case MotionEvent.ACTION_DOWN: { 
 
       mInitialMotionX = ev.getX(); 
 
       mInitialMotionY = ev.getY(); 
 
       break; 
 
      } 
 

 
      case MotionEvent.ACTION_MOVE: { 
 
       final float x = ev.getX(); 
 
       final float y = ev.getY(); 
 
       if (mInitialMotionX > mEdgeSlop && !isOpen() && canScroll(this, false, 
 
         Math.round(x - mInitialMotionX), Math.round(x), Math.round(y))) { 
 
    
 
        MotionEvent cancelEvent = MotionEvent.obtain(ev); 
 
        cancelEvent.setAction(MotionEvent.ACTION_CANCEL); 
 
        return super.onInterceptTouchEvent(cancelEvent); 
 
       } 
 
      } 
 
     } 
 

 
     return super.onInterceptTouchEvent(ev); 
 
    } 
 
}

像例如自定義SmartSlidingPane類,那麼你應該在你的XML使用自定義類像

<app.info.rashjz.amuse.adapter.SmartSlidingPane 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:id="@+id/slidingPanel" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent"> 
 

 

 
    <include layout="@layout/menu" /> 
 

 
    <LinearLayout 
 
     android:id="@+id/main" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_gravity="right" 
 
     android:orientation="vertical"> 
 

 

 

 
     <android.support.v4.view.ViewPager 
 
      xmlns:android="http://schemas.android.com/apk/res/android" 
 
      android:id="@+id/pager" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:background="@android:color/transparent"> 
 
     </android.support.v4.view.ViewPager> 
 

 
    </LinearLayout> 
 

 
</app.info.rashjz.amuse.adapter.SmartSlidingPane>

在定義SmartSlidingPane佈局您的主要活動如 (SmartSlidingPane)findViewById(R.id.slidingPanel); 那就是全部