Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple trans animation on android layout doesn't work for the second time


My xml file is as below

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100" >

<!-- top -->

  <LinearLayout
    android:id="@+id/top_container"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="60"
    android:background="@drawable/xxx" >

  </LinearLayout>

<!-- bottom -->

  <TableLayout
    android:id="@+id/bottom_container"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="40"
    android:background="@drawable/yyy"
    android:padding="20dip"
    android:stretchColumns="1"
    android:weightSum="2" >

    <TableRow>

     </TableRow>
   </TableLayout>
 </LinearLayout>

the animation file trans_from_bottom.xml

 <translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="1000"
    android:fromYDelta="100%"
    android:toYDelta="0%" />

the animation file trans_from_top.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="1000"
    android:fromYDelta="-100%"
    android:toYDelta="0%" />

trans_back_to_top.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="1000"
    android:fillAfter="true"
    android:fromYDelta="0%"
    android:toYDelta="-100%" />

trans_back_to_bottom.xml

 <translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="1000"
    android:fillAfter="true"
    android:fromYDelta="0%"
    android:toYDelta="100%" />

The simple class as below lines of code

    topCont =(LinearLayout)findViewById(R.id.top_container);
    botCont =(TableLayout)findViewById(R.id.bottom_container);

    Animation   slidedown = AnimationUtils.loadAnimation(A.this, R.anim.trans_from_top);
    topCont.setAnimation(slidedown);

    Animation   slideup = AnimationUtils.loadAnimation(A.this, R.anim.trans_from_bottom);
    botCont.setAnimation(slideup);


    topCont.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View arg0) {

            Animation   slideup = AnimationUtils.loadAnimation(A.this, R.anim.trans_back_to_top);
            topCont.setAnimation(slideup);


            Animation   slidedown = AnimationUtils.loadAnimation(A.this, R.anim.trans_back_to_bottom);
            botCont.setAnimation(slidedown);



        }
    });

I tried to give an Horizontal in and out type of animation, the click event animations doesn't fetch desired result.Please suggest what went wrong?

like image 393
ganesh Avatar asked Dec 04 '22 02:12

ganesh


1 Answers

I got the answer instead of setAnimation use startAnimation,every thing works fine as desired.

like image 134
ganesh Avatar answered Apr 16 '23 15:04

ganesh