Android expand animation on Button click -


i try make tests ux , animation. want @ click on button expand until button has size of parent layout. here simple interface :

enter image description here

i succeed create own animation, it's simple class takes begin x, end x, begin y , end y. here class :

import android.view.view; import android.view.animation.animation; import android.view.animation.transformation;  public class expandanimation extends animation {     protected final view view;     protected float pervalueh, pervaluew;     protected final int originalheight, originalwidth;      public expandanimation(view view, int fromheight, int toheight, int fromwidth, int towidth) {         this.view = view;         this.originalheight = fromheight;         this.originalwidth = fromwidth;         this.pervalueh = (toheight - fromheight);         this.pervaluew = (towidth - fromwidth);     }      @override     protected void applytransformation(float interpolatedtime, transformation t) {         view.getlayoutparams().height = (int) (originalheight + pervalueh * interpolatedtime);         view.getlayoutparams().width = (int) (originalwidth + (pervaluew * interpolatedtime)*2);         view.requestlayout();     }      @override     public boolean willchangebounds() {         return true;     } } 

the animation pretty , works expected :

enter image description here

here main loop :

import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.view.viewgroup; import android.widget.button;  public class mainactivity extends appcompatactivity {     private button left;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          left = (button) findviewbyid(r.id.left);         left.setlayertype(view.layer_type_software, null);         left.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 viewgroup parent = (viewgroup) view.getparent();                 expandanimation animation = new expandanimation(view, view.getbottom(), parent.gettop(), view.getleft(), parent.getright());                 animation.setduration(3000);                 animation.setfillafter(true);                 view.startanimation(animation);             }         });     } } 

but have 3 major issues :

  • first, text gone , don't know why...
  • on other hand, want animation come on others views, when tried wasn't working how can achieve ?
  • and last not least, @ end of animation, button gone , there ugly artefact... how can avoid ?

enter image description here

edit : layout :

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="mainactivity">      <linearlayout         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="150dp"         android:weightsum="3"         android:padding="15dp"         android:layout_alignparentbottom="true"         android:layout_centerhorizontal="true"         android:gravity="bottom">          <button             android:id="@+id/left"             android:layout_width="0dp"             android:layout_height="wrap_content"             android:layout_weight="1"             android:text="retenter"             android:textsize="15dp"             android:textcolor="#fff"             android:background="#ff33cc44" />      </linearlayout> </relativelayout> 

edit2 : artefact appears @ end of animation due method setlayertype(view.layer_type_software, null).

@override protected void applytransformation(float interpolatedtime, transformation t) {     view.getlayoutparams().height = (int) (originalheight + pervalueh * interpolatedtime);     view.getlayoutparams().width = (int) (originalwidth + (pervaluew * interpolatedtime));     view.requestlayout(); } 

remove *2 result below.

enter image description here


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -