title: View Drag Helper helper
body: <p>I am trying to get the <code>ViewDragHelper</code> to work with a vertical <code>LinearLayout</code>, - Container - which has </p>
  
  <pre><code>A ---- List View
  B ---- horizontal linear layout 
  C ---- Support Map Fragment
  </code></pre>
  
  <p>as children views.</p>
  
  <p>A has <code>layout_height="0dp"</code>. Pulling down on B, should proportionally increase the height of A, there by revealing the contents on the <code>ListView</code>, thereby automatically re positioning B and resizing C in the process.</p>
  
  <p>The following is the code for the Container <code>LinearLayout</code>.</p>
  
  <pre><code>public class MyLinearLayout extends LinearLayout {
  
  private LinearLayout headerLayout;
  private ListView filtersListView;
  
  private ViewDragHelper viewDragHelper;
  private int MARGIN;
  
  public MyLinearLayout (Context context) {
      super(context);
      init();
  }
  
  public MyLinearLayout (Context context, AttributeSet attrs) {
      super(context, attrs);
      init();
  }
  
  public MyLinearLayout (Context context, AttributeSet attrs, int defStyleAttr) {
      super(context, attrs, defStyleAttr);
      init();
  }
  
  private void init() {
      viewDragHelper = ViewDragHelper.create(this, 1, new DragHelperCallback());
      float GESTURE_THRESHOLD_DP = 10.0f;
      float scale = getResources().getDisplayMetrics().density;
  
      MARGIN = (int) (GESTURE_THRESHOLD_DP * scale + 0.5f);
  }
  
  @Override
  protected void onFinishInflate() {
      Log.i("Places", "onFinishInflate");
      super.onFinishInflate();
  
      headerLayout = (LinearLayout) findViewById(R.id.header);
      filtersListView = (ListView) findViewById(R.id.filters_list);
  }
  
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
      Log.i("Places", "onInterceptTouchEvent");
      return viewDragHelper.shouldInterceptTouchEvent(ev);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
      Log.i("Places", "onTouchEvent");
      viewDragHelper.processTouchEvent(event);
  
      LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) event.getRawY());
      layoutParams.setMargins(MARGIN, MARGIN, MARGIN, MARGIN);
      filtersListView.setLayoutParams(layoutParams);
  
      return true;
  }
  
  private class DragHelperCallback extends ViewDragHelper.Callback {
  
      @Override
      public boolean tryCaptureView(View child, int pointerId) {
          Log.i("Places", "tryCaptureView " + (child == headerLayout));
          return child == headerLayout;
      }
  
      @Override
      public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
          Log.i("Places", "onViewPositionChanged " + changedView.getClass().getName());
          super.onViewPositionChanged(changedView, left, top, dx, dy);
      }
  
      @Override
      public void onViewReleased(View releasedChild, float xvel, float yvel) {
          Log.i("Places", "onViewReleased " + releasedChild.getClass().getName());
          super.onViewReleased(releasedChild, xvel, yvel);
      }
  }
  }
  </code></pre>
  
  <p>I have looked at the the following.</p>
  
  <p><a href="https://stackoverflow.com/questions/17772532/viewdraghelper-how-to-use-it">ViewDragHelper: how to use it?</a></p>