Android布局上的简单转换动画第二次不起作用

gan*_*esh 4 android android-animation android-layout


我的xml文件如下

 <?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>
Run Code Online (Sandbox Code Playgroud)

动画文件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%" />
Run Code Online (Sandbox Code Playgroud)

动画文件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%" />
Run Code Online (Sandbox Code Playgroud)

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%" />
Run Code Online (Sandbox Code Playgroud)

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%" />
Run Code Online (Sandbox Code Playgroud)

简单的类如下面的代码行

    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);



        }
    });
Run Code Online (Sandbox Code Playgroud)

我尝试给出一个水平输入和输出类型的动画,点击事件动画无法获取所需的结果.请指出出了什么问题?

gan*_*esh 16

我得到了答案而不是setAnimation使用startAnimation,每个东西都可以正常工作.

  • 谢谢你的回答.它为我这么简单的工作节省了几个小时. (4认同)