android - Running simultaneous animations on LinearLayout weight with ValueAnimator -



android - Running simultaneous animations on LinearLayout weight with ValueAnimator -

i've tried many different approaches , none of them have worked. i'm open suggestion.

i making custom "button". it's not of type button behave multi-state button. each button has 3 differently colored glyphs represent different states (blue, white, , orange). whichever glyph in primary state much larger others, so:

at moment, each "button" linearlayout 3 imageviews , each imageview populated pathshape drawable weights 0.2 + 0.6 + 0.2 = 1.0. part works fine. 0.6 primary state weight.

i have simple button on screen trigger animation. animation cut down current primary 0.6 weight 0.2 weight, , new primary 0.2 0.6. 1 shrinks, other grows.

problem: animations not run simultaneously, though i've explicitly told them run simultaneously. first 1 shrinks 0.6 0.2, there slight pause, , sec 1 grows 0.2 0.6.

button button = (button)this.findviewbyid(r.id.shift); button.setonclicklistener(new view.onclicklistener() { public animator makeweightanimator(final view v, float startingweight, float endingweight) { long duration = 2000; valueanimator va = valueanimator.offloat(startingweight, endingweight); va.setduration(duration); va.addupdatelistener(new valueanimator.animatorupdatelistener() { public void onanimationupdate(valueanimator animation) { float value = (float) animation.getanimatedvalue(); linearlayout.layoutparams paramsanim = (linearlayout.layoutparams)v.getlayoutparams(); paramsanim.weight = value.floatvalue(); v.requestlayout(); } }); homecoming va; } @override public void onclick(view v) { float newblueweight = 0.2f; float newwhiteweight = 0.2f; float neworangeweight = 0.2f; if (state == 0) { // create bluish larger newblueweight = 0.6f; } else if (state == 1) { // create white larger newwhiteweight = 0.6f; } else { // create orange larger neworangeweight = 0.6f; } // total 0.2 + 0.6 + 0.2 = 1.0 list<animator> animators = new linkedlist<animator>(); linearlayout.layoutparams blueparams = (linearlayout.layoutparams)blueimage.getlayoutparams(); log.d("ta", string.format("blue %f -> %f", blueparams.weight, newblueweight)); if (math.abs(blueparams.weight - newblueweight) > 0.001) { // new weight different existing weight animator va = makeweightanimator(blueimage, blueparams.weight, newblueweight); animators.add(va); } linearlayout.layoutparams whiteparams = (linearlayout.layoutparams)whiteimage.getlayoutparams(); log.d("ta", string.format("white %f -> %f", whiteparams.weight, newwhiteweight)); if (math.abs(whiteparams.weight - newwhiteweight) > 0.001) { // new weight different existing weight animator va = makeweightanimator(whiteimage, whiteparams.weight, newwhiteweight); animators.add(va); } linearlayout.layoutparams orangeparams = (linearlayout.layoutparams)orangeimage.getlayoutparams(); log.d("ta", string.format("orange %f -> %f", orangeparams.weight, neworangeweight)); if (math.abs(orangeparams.weight - neworangeweight) > 0.001) { // new weight different existing weight animator va = makeweightanimator(orangeimage, orangeparams.weight, neworangeweight); animators.add(va); } if (animators.size() > 0) { animatorset s = new animatorset(); s.playtogether(animators); s.start(); } state++; if (state > 2) { state = 0; } } });

here video made showing animations running sequentially instead of in parallel:

http://inadaydevelopment.com/stackoverflow/androidlinearlayoutanimation.html

i have tried combining of changes downwards 1 animator instead of trying have multiple animators running parallel, animations still happen sequentially. sense i'm losing mind:

public animator makesimultaneousanimator(final viewgroup parentviewgroup, final view growingview, final view shrinkingview, final view otherview, float startingweight, float endingweight) { long duration = 2000; valueanimator va = valueanimator.offloat(startingweight, endingweight); va.setduration(duration); va.addupdatelistener(new valueanimator.animatorupdatelistener() { public void onanimationupdate(valueanimator animation) { float value = (float) animation.getanimatedvalue(); float growingweight = value.floatvalue(); linearlayout.layoutparams growingparams = (linearlayout.layoutparams)growingview.getlayoutparams(); linearlayout.layoutparams shrinkingparams = (linearlayout.layoutparams)shrinkingview.getlayoutparams(); linearlayout.layoutparams otherparams = (linearlayout.layoutparams)otherview.getlayoutparams(); float otherweight = otherparams.weight; float shrinkingweight = 1.0f - growingweight - otherweight; growingparams.weight = growingweight; shrinkingparams.weight = shrinkingweight; parentviewgroup.requestlayout(); //growingview.requestlayout(); //shrinkingview.requestlayout(); } }); homecoming va; }

i'd maintain reference big imageview, follow it. every time event fired, decrease big 1 , increment one.

i've done illustration click listener on each imageview within linearlayout.

the big 1 middle imageview , it's weight pre-set 0.6 while others have @ 0.2.

code: private static final float from_weight = 0.2f; private static final float to_weight = 0.6f; private static final int duration = 500; private view v1, v2, v3, big; private view.onclicklistener clicklistener = new view.onclicklistener() { @override public void onclick(view v) { if (v == big) { return; } else if (v1 == big) { animate(v1, to_weight, from_weight); } else if (v2 == big) { animate(v2, to_weight, from_weight); } else if (v3 == big) { animate(v3, to_weight, from_weight); } big = v; animate(v, from_weight, to_weight); } }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); v1 = findviewbyid(r.id.tv1); big = v2 = findviewbyid(r.id.tv2); v3 = findviewbyid(r.id.tv3); v1.setonclicklistener(clicklistener); v2.setonclicklistener(clicklistener); v3.setonclicklistener(clicklistener); } private void animate(final view v, float from, float to) { valueanimator va = valueanimator.offloat(from, to); va.setduration(duration); va.addupdatelistener(new valueanimator.animatorupdatelistener() { public void onanimationupdate(valueanimator animation) { float growingweight = (float) animation.getanimatedvalue(); linearlayout.layoutparams params = (linearlayout.layoutparams) v.getlayoutparams(); params.weight = growingweight; v.setlayoutparams(params); } }); va.start(); } layout: <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <imageview android:background="#00ffff" android:layout_weight="0.2" android:id="@+id/tv1" android:layout_width="100dp" android:layout_height="0dp"/> <imageview android:background="#ffff00" android:layout_weight="0.6" android:id="@+id/tv2" android:layout_width="100dp" android:layout_height="0dp"/> <imageview android:background="#ff00ff" android:layout_weight="0.2" android:id="@+id/tv3" android:layout_width="100dp" android:layout_height="0dp"/> </linearlayout> effect:

android android-linearlayout android-animation

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -