java - set height view to match parent with animation in android -


how change height of view match_parent when there click?

public class resizeanimation extends animation {     final int startheight;     final int targetheight;     private final boolean isopen;     view view;      public resizeanimation(view view, int height, boolean isopen) {         this.view = view;         this.targetheight = height;         this.isopen = isopen;         startheight = view.getheight();     }      @override      protected void applytransformation(float interpolatedtime, transformation t) {         int newheight;         if (isopen) {             newheight = (int) (startheight + (targetheight - startheight) * interpolatedtime);         } else {             newheight =  (int) (startheight + targetheight * interpolatedtime);         }         view.getlayoutparams().height = newheight;         view.requestlayout();     }      @override     public void initialize(int width, int height, int parentwidth, int parentheight) {         super.initialize(width, height, parentwidth, parentheight);     }      @override     public boolean willchangebounds() {         return true;     } } 

resizeanimation resizeanimation = new resizeanimation(view, match_parent, false); resizeanimation.setduration(500); view.startanimation(resizeanimation); 

your animation doesn't work because passing view.match_parent(which value -1) target height. quoting documentation:

int match_parent [...] constant value: -1 (0xffffffff)

you have pass real target height. can accomplish measuring future target height in parent layout after has been rendered (i recommend viewtreeobserver.ongloballayout() that).


Comments

Popular posts from this blog

javascript - Knockout pushing observable and computed data to an observable array -

'hasOwnProperty' in javascript -

Trouble making a JSON string -