Skip to content Skip to sidebar Skip to footer

Animate View On Button Click Android

I have a button and on that button i wanna slide a view below.That view contains 2 buttons to open camera and gallery.To achieve this i have used translate animation but i am not

Solution 1:

you don't need slide animation, what you actually want is object animation

Code

Buttonbt= (Button) findViewById (R.id.button);
    finalLinearLayoutlinearLayout= (LinearLayout) findViewById (R.id.test);
    bt.setOnClickListener (newView.OnClickListener () {
        @OverridepublicvoidonClick(View v) {

            ValueAnimatoranim= ValueAnimator.ofInt(linearLayout.getMeasuredHeight (), 500);
            anim.addUpdateListener(newValueAnimator.AnimatorUpdateListener() {
                @OverridepublicvoidonAnimationUpdate(ValueAnimator valueAnimator) {
                    intval= (Integer) valueAnimator.getAnimatedValue();
                    ViewGroup.LayoutParamslayoutParams= linearLayout.getLayoutParams();
                    layoutParams.height = val;
                    linearLayout.setLayoutParams(layoutParams);
                }
            });
            anim.setDuration(1000);
            anim.start(); 
        }
    });

XML

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="New Button"android:id="@+id/button"android:layout_gravity="center_horizontal" /><LinearLayoutandroid:orientation="vertical"android:layout_width="match_parent"android:layout_height="0dp"android:id="@+id/test"android:background="#fff333"android:layout_gravity="center_horizontal"><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="New Button"android:id="@+id/button2" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="New Button"android:id="@+id/button3" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="New Button"android:id="@+id/butt3" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="New Button"android:id="@+id/bton3" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="New Button"android:id="@+id/butn3" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="New Button"android:id="@+id/cb" /></LinearLayout></LinearLayout>

Post a Comment for "Animate View On Button Click Android"