Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewDragHelper - Child layout changes ignored while dragging

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: http://imgur.com/a/dDiGt

like image 964
Richard Avatar asked Aug 01 '16 07:08

Richard


1 Answers

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).

like image 93
Naveen Dissanayake Avatar answered Nov 13 '22 06:11

Naveen Dissanayake