当前位置:K88软件开发文章中心编程语言APP编程Android01 → 文章内容

8.4.2 Android动画合集之补间动画

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-12 6:27:43

rty),就是动画文件的根标签要是:<objectAnimator>,<valueAnimator>或者是前面两者放到一个<set>里;v4包下的Fragment:v4包下的则支持两种setCustomAnimations()另外要注意一点的是,对应的动画类型是:补间动画(Tween),和上面的View一样~可能你会有疑惑,你怎么知道对应的动画类型,其实只要你到Fragment源码那里找下:onCreateAnimation()方法的一个返回值就知道了:v4包:app包:7.为Activity设置过场动画Activty设置过场动画非常简单,调用的方法是:overridePendingTransition(int enterAnim, int exitAnim)用法很简单:在startActivity(intent)或者finish()后添加参数依次是:新Activity进场时的动画,以及旧Activity退场时的动画下面提供几种比较简单而且常用的过场动画供大家使用~下载传送门:Activity常用过渡动画.zip8.写个进入APP后登陆注册按钮从底部弹出动画效果的例子:运行效果图:代码实现:首先是我们的布局文件:activity_main.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:background="#DDE2E3" tools:context=".MainActivity"> <LinearLayout android:id="@+id/start_ctrl" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="vertical" android:visibility="gone"> <Button android:id="@+id/start_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#F26968" android:gravity="center" android:paddingBottom="15dp" android:paddingTop="15dp" android:text="登陆" android:textColor="#FFFFFF" android:textSize="18sp" /> <Button android:id="@+id/start_register" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#323339" android:gravity="center" android:paddingBottom="15dp" android:paddingTop="15dp" android:text="注册" android:textColor="#FFFFFF" android:textSize="18sp" /> </LinearLayout></RelativeLayout>接着是MainActivity.java:public class MainActivity extends AppCompatActivity { private LinearLayout start_ctrl; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); start_ctrl = (LinearLayout) findViewById(R.id.start_ctrl); //设置动画,从自身位置的最下端向上滑动了自身的高度,持续时间为500ms final TranslateAnimation ctrlAnimation = new TranslateAnimation( TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 1, TranslateAnimation.RELATIVE_TO_SELF, 0); ctrlAnimation.setDuration(500l); //设置动画的过渡时间 start_ctrl.postDelayed(new Runnable() { @Override public void run() { start_ctrl.setVisibility(View.VISIBLE); start_ctrl.startAnimation(ctrlAnimation); } }, 2000); }}注释写得很清楚了,这里就不BB解释了,如果你对TranslateAnimation.RELATIVE_TO_SELF这个有疑惑,请自己谷歌或者百度,限于篇幅(我懒),这里就不写了,蛮简单的~9.本节代码示例下载AnimationDemo3.zipAnimationDemo4.zip本节小结:本节给大家细细地讲解了下Android中的第二种动画(渐变动画),四种动画的详解,以及设置动画监听器,还有如何为View,Fragment和Activity设置动画,最后还写了一个进入后从APP底部弹出登陆按钮和注册按钮的例子,篇幅可能有点长,不过都非常容易理解,相信大家看完都能够收获满满~!好的,本节就到这里,谢谢~

上一页  [1] [2] [3] 


8.4.2 Android动画合集之补间动画