Created
April 4, 2016 17:57
-
-
Save vmax/d3acf0c789b009ec4367bb2cbaffde47 to your computer and use it in GitHub Desktop.
A wrapper for animating changes of android:weight property of views inside LinearLayout using ObjectAnimator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ViewWeightAnimationWrapper { | |
private View view; | |
public ViewWeightAnimationWrapper(View view) { | |
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) { | |
this.view = view; | |
} else { | |
throw new IllegalArgumentException("The view should have LinearLayout as parent"); | |
} | |
} | |
public void setWeight(float weight) { | |
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); | |
params.weight = weight; | |
view.setLayoutParams(params); | |
} | |
public float getWeight() { | |
return ((LinearLayout.LayoutParams) view.getLayoutParams()).weight; | |
} | |
} | |
// code sample | |
ObjectAnimator.ofFloat(new ViewWeightAnimationWrapper(view), "weight", oldWeight, newWeight).start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment