16

I'm trying to apply margin updates or animations to a child view which parent is dragged using a ViewDragHelper.

However the updated layout properties have no effect and are not rendered while the view is dragged. Everything from adding and removing views, to layout animations or layout param updates are ignored while dragging:

To illustrate this issue, i've created a delayed runnable which updates the height of a view (the green view) after 3 seconds:

spacer.postDelayed(new Runnable() {
     @Override
     public void run() {
          Log.d(TAG,"set layout params!!!!");
          ViewGroup.LayoutParams spacerParams = spacer.getLayoutParams();
          spacerParams.height = (int) (200+(Math.random()*200));
          spacer.setLayoutParams(spacerParams);
     }
},3000);

Check this demo screen recording: https://i.stack.imgur.com/eDzXE.jpg

Richard
  • 14,427
  • 9
  • 57
  • 85
  • 1
    To my knowledge, ViewDragHelper only offsets the dragged View's translation values, it doesn't actually make changes that cause a re-layout. – Karakuri Aug 03 '16 at 09:01
  • "View, dragged using a `ViewDragHelper`" is a very vague description. Is that a custom component? How do you actually use it? – user1643723 Nov 01 '16 at 07:10
  • @user1643723 https://developer.android.com/reference/android/support/v4/widget/ViewDragHelper.html – Richard Nov 01 '16 at 18:57

1 Answers1

1

Android only ready LayoutParams when its doing a layout pass which does not happen when View is being moved. If you want to change the size of the View while its animating you should use setScale instead. If you really need your View to re-run its layout you can manually call layout(left, top, right, bottom).