android - Center vector with animation -
i have vector i'm trying scale bigger after click on it, position in top left corner of viewport area want have in center, , animation should make bigger center of bottom. i'm using pivot doesn't help. code:
activity:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_baloon); androidimageview = (imageview) findviewbyid(r.id.animated); if (androidimageview != null) { androidimageview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (isbig) { animatedown(); isbig = false; } else { animateup(); isbig = true; } } }); } } private void animateup() { objectanimator scaledownx = objectanimator.offloat(androidimageview, "scalex", 1.5f); objectanimator scaledowny = objectanimator.offloat(androidimageview, "scaley", 1.5f); scaledownx.setduration(300); scaledowny.setduration(300); animatorset scaledown = new animatorset(); scaledown.play(scaledownx).with(scaledowny); scaledown.start(); } private void animatedown() { objectanimator scaledownx = objectanimator.offloat(androidimageview, "scalex", 1.0f); objectanimator scaledowny = objectanimator.offloat(androidimageview, "scaley", 1.0f); scaledownx.setduration(300); scaledowny.setduration(300); animatorset scaledown = new animatorset(); scaledown.play(scaledownx).with(scaledowny); scaledown.start(); }
layout:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" > <relativelayout android:layout_width="100dp" android:layout_height="100dp" android:layout_centerinparent="true" android:background="@android:color/white" > <imageview android:id="@+id/animated" android:layout_width="100dp" app:srccompat="@drawable/animated_baloon" android:layout_height="100dp" android:layout_centerinparent="true" /> </relativelayout>
vector:
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="48dp" android:viewportheight="327.5" android:viewportwidth="262.36" android:width="48dp" > <group android:name="android" android:pivotx="163.75" android:pivoty="131.18" > <path android:fillcolor="#fdc500" android:pathdata="m-0.01,32.82a32.81,32.81 0,1 1,65.61 0c0,28.94 -32.8,49.04 -32.8,49.04s-0.01,61.77 -0.01,32.82z" /> </group>
you need use viewport height , width, not android:height
and width
.
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportheight="81.875" android:viewportwidth="32.795" android:width="24dp" > <!-- <group name="dot_name" pivotx="viewportheight / 2" pivoty="viewportwidth / 2"> calculate values yourself, write calucalted values in there. moves reference point middle --> <group name="dot_name" pivotx="40.9375" pivoty="viewportwidth / 2"> <path android:fillcolor="#ff000000" android:pathdata="m-0.01,32.82a32.81,32.81 0,1 1,65.61 0c0,28.94 -32.8,49.04 -32.8,49.04s-0.01,61.77 -0.01,32.82z" /> </group> </vector>
Comments
Post a Comment