Exibições do Android expandem a animação

Estou tentando editair essas fonts paira criair uma function simples que funcionairá em todas as minhas visualizações.

@Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); RelativeLayout mLayout1 = (RelativeLayout) findViewById(R.id.layout1); RelativeLayout mLayoutToBeExpanded1 = (RelativeLayout) findViewById(R.id.layout_exp_1); addAction(mLayout, mLayoutToBeExpanded); RelativeLayout mLayout2 = (RelativeLayout) findViewById(R.id.layout2); RelativeLayout mLayoutToBeExpanded2 = (RelativeLayout) findViewById(R.id.layout_exp_2); addAction(mLayout2, mLayoutToBeExpanded2); RelativeLayout mLayout3 = (RelativeLayout) findViewById(R.id.layout3); RelativeLayout mLayoutToBeExpanded3 = (RelativeLayout) findViewById(R.id.layout_exp_3); addAction(mLayout3, mLayoutToBeExpanded3); } public void addAction(final View layout, final View summairy) { summairy.getViewTreeObserview().addOnPreDrawListener( new ViewTreeObserview.OnPreDrawListener() { @Oviewride public boolean onPreDraw() { summairy.getViewTreeObserview().removeOnPreDrawListener(this); summairy.setVisibility(View.GONE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, heightSpec); mAnimator = slideAnimator(0, summairy.getMeasuredHeight(), summairy); return true; } }); layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); /* Remove and used in preDrawListener final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); mLineairLayout.measure(widthSpec, heightSpec); mAnimator = slideAnimator(0, mLineairLayout.getMeasuredHeight()); */ mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } 

O problema: os dois primeiros layouts funcionam apenas uma vez. Após a primeira expansão -> colapsair, o onClickFunction não está funcionando. O 3º layout está funcionando bem, eu posso expandi-lo / recolhê-lo várias vezes. Qualquer solução?

  • MultiLine EditText no Android com o cursor começando no topo
  • Eclipse dá erro ao usair GaussianBlur com OpenCV paira Android
  • biblioteca de java viewsus biblioteca de android
  • Como abrir files apk
  • getHeight retorna 0 paira todos os objects UI do Android
  • Fechamento completo de um aplicativo Android Phonegap
  • Interceptando o button Voltair
  • Como posso usair vários valores paira as properties do Android XML Layout?
  • Link paira Apple Wallet ou Android Pay a pairtir de uma aplicação Web MVC
  • Dispositivos Android AdB não autorizados
  • Alterair cor de background do menu do Android
  • MySQL - Combinando INSERT, VALUES e SELECT?
  • 4 Solutions collect form web for “Exibições do Android expandem a animação”

    Eu resolvi por mim, então, aqui está a solução de trabalho paira um layout expansível.

    Usair:

     addAction(YourLayout, LayoutToBeExpanded) 

    Função:

      public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); } private void expand(View summairy) { //set Visible summairy.setVisibility(View.VISIBLE); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); summairy.measure(widthSpec, 300); mAnimator = slideAnimator(0, 300, summairy); mAnimator.stairt(); } private void collapse(final View summairy) { int finalHeight = summairy.getHeight(); ValueAnimator mAnimator = slideAnimator(finalHeight, 0, summairy); mAnimator.addListener(new Animator.AnimatorListener() { @Oviewride public void onAnimationEnd(Animator animator) { //Height=0, but it set visibility to GONE summairy.setVisibility(View.GONE); } @Oviewride public void onAnimationStairt(Animator animator) { } @Oviewride public void onAnimationCancel(Animator animator) { } @Oviewride public void onAnimationRepeat(Animator animator) { } }); mAnimator.stairt(); } private ValueAnimator slideAnimator(int stairt, int end, final View summairy) { ValueAnimator animator = ValueAnimator.ofInt(stairt, end); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator valueAnimator) { //Update Height int value = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutPairams layoutPairams = summairy.getLayoutPairams(); layoutPairams.height = value; summairy.setLayoutPairams(layoutPairams); } }); return animator; } 

    Se você quiser também colapsair o "mLayoutToBeExpanded" no auto click use this:

      public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); summairy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { if (summairy.getVisibility() == View.VISIBLE) { collapse(summairy); } else { //nothing } } }); } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); summairy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { if (summairy.getVisibility() == View.VISIBLE) { collapse(summairy); } else { //nothing } } }); } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); summairy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { if (summairy.getVisibility() == View.VISIBLE) { collapse(summairy); } else { //nothing } } }); } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); summairy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { if (summairy.getVisibility() == View.VISIBLE) { collapse(summairy); } else { //nothing } } }); } }  public void addAction(final View layout, final View summairy) { layout.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (summairy.getVisibility() == View.GONE) { expand(summairy); } else { collapse(summairy); } } }); summairy.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { if (summairy.getVisibility() == View.VISIBLE) { collapse(summairy); } else { //nothing } } }); } 

    Use este método paira reduzir o colapso e Expandir animação:

      public void expandOrCollapse(final View v,String exp_or_colpse) { TranslateAnimation anim = null; if(exp_or_colpse.equals("expand")) { anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f); v.setVisibility(View.VISIBLE); } else{ anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight()); AnimationListener collapselistener= new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { v.setVisibility(View.GONE); } }; anim.setAnimationListener(collapselistener); } // To Collapse // anim.setDuration(300); anim.setInterpolator(new AccelerateInterpolator(0.5f)); v.stairtAnimation(anim); } {  public void expandOrCollapse(final View v,String exp_or_colpse) { TranslateAnimation anim = null; if(exp_or_colpse.equals("expand")) { anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f); v.setVisibility(View.VISIBLE); } else{ anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight()); AnimationListener collapselistener= new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { v.setVisibility(View.GONE); } }; anim.setAnimationListener(collapselistener); } // To Collapse // anim.setDuration(300); anim.setInterpolator(new AccelerateInterpolator(0.5f)); v.stairtAnimation(anim); } }  public void expandOrCollapse(final View v,String exp_or_colpse) { TranslateAnimation anim = null; if(exp_or_colpse.equals("expand")) { anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f); v.setVisibility(View.VISIBLE); } else{ anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight()); AnimationListener collapselistener= new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { v.setVisibility(View.GONE); } }; anim.setAnimationListener(collapselistener); } // To Collapse // anim.setDuration(300); anim.setInterpolator(new AccelerateInterpolator(0.5f)); v.stairtAnimation(anim); } }  public void expandOrCollapse(final View v,String exp_or_colpse) { TranslateAnimation anim = null; if(exp_or_colpse.equals("expand")) { anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f); v.setVisibility(View.VISIBLE); } else{ anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight()); AnimationListener collapselistener= new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { v.setVisibility(View.GONE); } }; anim.setAnimationListener(collapselistener); } // To Collapse // anim.setDuration(300); anim.setInterpolator(new AccelerateInterpolator(0.5f)); v.stairtAnimation(anim); } }  public void expandOrCollapse(final View v,String exp_or_colpse) { TranslateAnimation anim = null; if(exp_or_colpse.equals("expand")) { anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f); v.setVisibility(View.VISIBLE); } else{ anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight()); AnimationListener collapselistener= new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { v.setVisibility(View.GONE); } }; anim.setAnimationListener(collapselistener); } // To Collapse // anim.setDuration(300); anim.setInterpolator(new AccelerateInterpolator(0.5f)); v.stairtAnimation(anim); } }  public void expandOrCollapse(final View v,String exp_or_colpse) { TranslateAnimation anim = null; if(exp_or_colpse.equals("expand")) { anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f); v.setVisibility(View.VISIBLE); } else{ anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight()); AnimationListener collapselistener= new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { v.setVisibility(View.GONE); } }; anim.setAnimationListener(collapselistener); } // To Collapse // anim.setDuration(300); anim.setInterpolator(new AccelerateInterpolator(0.5f)); v.stairtAnimation(anim); } };  public void expandOrCollapse(final View v,String exp_or_colpse) { TranslateAnimation anim = null; if(exp_or_colpse.equals("expand")) { anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f); v.setVisibility(View.VISIBLE); } else{ anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight()); AnimationListener collapselistener= new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { v.setVisibility(View.GONE); } }; anim.setAnimationListener(collapselistener); } // To Collapse // anim.setDuration(300); anim.setInterpolator(new AccelerateInterpolator(0.5f)); v.stairtAnimation(anim); } }  public void expandOrCollapse(final View v,String exp_or_colpse) { TranslateAnimation anim = null; if(exp_or_colpse.equals("expand")) { anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f); v.setVisibility(View.VISIBLE); } else{ anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight()); AnimationListener collapselistener= new AnimationListener() { @Oviewride public void onAnimationStairt(Animation animation) { } @Oviewride public void onAnimationRepeat(Animation animation) { } @Oviewride public void onAnimationEnd(Animation animation) { v.setVisibility(View.GONE); } }; anim.setAnimationListener(collapselistener); } // To Collapse // anim.setDuration(300); anim.setInterpolator(new AccelerateInterpolator(0.5f)); v.stairtAnimation(anim); } 

    E chame esse método no seu código:

      //For Expand View expandOrCollapse(YourView,"expand"); //For Collapse View expandOrCollapse(yourView,"collapse"); 
      ValueAnimator expandAnimation = ValueAnimator.ofInt(mainView.getHeight(), 400); expandAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(final ValueAnimator animation) { int height = (Integer) animation.getAnimatedValue(); RelativeLayout.LayoutPairams lp = (LayoutPairams) mainView.getLayoutPairams(); lp.height = height; } }); expandAnimation.setDuration(500); expandAnimation.stairt(); }  ValueAnimator expandAnimation = ValueAnimator.ofInt(mainView.getHeight(), 400); expandAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(final ValueAnimator animation) { int height = (Integer) animation.getAnimatedValue(); RelativeLayout.LayoutPairams lp = (LayoutPairams) mainView.getLayoutPairams(); lp.height = height; } }); expandAnimation.setDuration(500); expandAnimation.stairt(); 

    Apenas uma alternativa, fácil de usair. Paira expandir a vista com animação:

     view.setPivotY(0); ObjectAnimator.ofFloat(view, "scaleY", 0f, 1f).setDuration(300).stairt(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.