Android LinearLayout expand -


i using following code expand particular linearlayout , following tutorial http://gmariotti.blogspot.sg/2013/09/expand-and-collapse-animation.html

but animation not smooth, reason why?

layout xml

<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" android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin"     tools:context="com.techiequickie.bharath.parsetest.newbet">      <linearlayout         android:id = "@+id/mainlinear"         android:orientation="vertical"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:layout_alignparenttop="true"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true"         android:padding="30px"         android:weightsum="1">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/bet_name_text"             android:id="@+id/tv_betname"             android:textsize="@dimen/text_size_general"/>          <edittext             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:id="@+id/et_betname" />          <spinner             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:id="@+id/spin_betcat1"             android:spinnermode="dropdown"             android:entries="@array/bet_categories"/>          <spinner             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:id="@+id/spin_betcat2"             android:spinnermode="dropdown"             android:paddingtop="@dimen/spin_categories_space_between"             android:entries="@array/bet_categories2"/>          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/bet_value_text"             android:id="@+id/bv_betvalue"             android:textsize="@dimen/text_size_general"/>          <seekbar             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:id="@+id/sb_betvalue"             android:max="10"             android:progress="0"             android:indeterminate="false" />          <linearlayout             android:orientation="horizontal"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_weight="0.15">              <switch                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="real bet"                 android:id="@+id/switch_betreal"                 android:checked="false" />         </linearlayout>          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/bet_description"             android:id="@+id/textview6"             android:textsize="@dimen/text_size_general" />     <linearlayout         android:id="@+id/collapsable"         android:orientation="horizontal"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="0.71">          <edittext             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:inputtype="textmultiline"             android:ems="10"             android:id="@+id/edittext2"             android:layout_weight="1" />     </linearlayout>          <button             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_placebet"             android:layout_gravity="center_horizontal"             android:text="@string/place_bet_button" />      </linearlayout> </relativelayout> 

activity class

package com.techiequickie.bharath.parsetest;  import android.animation.*; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.linearlayout;   public class newbet extends actionbaractivity {      linearlayout mainlayout, collapsablelayout;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_new_bet);          mainlayout = (linearlayout) findviewbyid(r.id.mainlinear);         collapsablelayout = (linearlayout) findviewbyid(r.id.collapsable);          collapsablelayout.setvisibility(view.gone);          mainlayout.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 if(collapsablelayout.getvisibility()==view.gone)                 {                     expand();                 }                 else                 {                     collapse();                 }             }         });     }      private void expand()     {         collapsablelayout.setvisibility(view.visible);          final int widthspec = view.measurespec.makemeasurespec(0, view.measurespec.unspecified);         final int heightspec = view.measurespec.makemeasurespec(0, view.measurespec.unspecified);         collapsablelayout.measure(widthspec, heightspec);          valueanimator manimator = slideanimator(0, collapsablelayout.getmeasuredheight());         manimator.start();     }      private void collapse() {         int finalheight = collapsablelayout.getheight();          valueanimator manimator = slideanimator(finalheight, 0);          manimator.addlistener(new animator.animatorlistener() {             @override             public void onanimationstart(animator animation) {              }              @override             public void onanimationend(animator animator) {                 //height=0, set visibility gone                 collapsablelayout.setvisibility(view.gone);             }              @override             public void onanimationcancel(animator animation) {              }              @override             public void onanimationrepeat(animator animation) {              }          });         manimator.start();     }      private valueanimator slideanimator(int start, int end)     {          valueanimator animator = valueanimator.ofint(start, end);          animator.addupdatelistener(new valueanimator.animatorupdatelistener() {             @override             public void onanimationupdate(valueanimator valueanimator) {                 //update height                 int value = (integer) valueanimator.getanimatedvalue();                 viewgroup.layoutparams layoutparams = collapsablelayout.getlayoutparams();                 layoutparams.height = value;                 collapsablelayout.setlayoutparams(layoutparams);             }         });         return animator;     }       @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_new_bet, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     } } 

try adding android:animatelayoutchanges="true" linear layout


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -