一种可以设置滑动动画的控件,只显示一行布局,在布局文件中的ViewFlipper控件中顺序写好每一行的布局
(1).MainActivity.java:
1
2
3
4
5
6
|
ViewFlipper mFlipper = ((ViewFlipper) this .findViewById(R.id.flipper)); mFlipper.startFlipping(); // 设置进入动画 mFlipper.setInAnimation(AnimationUtils.loadAnimation( this , R.anim.push_up_in)); // 设置滚出动画 mFlipper.setOutAnimation(AnimationUtils.loadAnimation( this , R.anim.push_up_out)); |
(2).activity_main.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<ViewFlipper android:id= "@+id/flipper" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginBottom= "20dip" android:flipInterval= "3000" > // 设置滑动间隔时间(毫秒) <TextView android:layout_width= "match_parent" android:layout_height= "wrap_content" android:gravity= "center_horizontal" android:text= "@string/animation_2_text_1" android:textSize= "26sp" /> <TextView android:layout_width= "match_parent" android:layout_height= "wrap_content" android:gravity= "center_horizontal" android:text= "@string/animation_2_text_2" android:textSize= "26sp" /> <TextView android:layout_width= "match_parent" android:layout_height= "wrap_content" android:gravity= "center_horizontal" android:text= "@string/animation_2_text_3" android:textSize= "26sp" /> </ViewFlipper> |
(3).push_up_in.xml:(动画资源文件)
1
2
3
4
|
< set xmlns:android = "http://schemas.android.com/apk/res/android" > < translate android:fromYDelta = "100%p" android:toYDelta = "0" android:duration = "300" /> < alpha android:fromAlpha = "0.0" android:toAlpha = "1.0" android:duration = "300" /> </ set > |
push_up_out.xml:
1
2
3
4
|
< set xmlns:android = "http://schemas.android.com/apk/res/android" > < translate android:fromYDelta = "0" android:toYDelta = "-100%p" android:duration = "300" /> < alpha android:fromAlpha = "1.0" android:toAlpha = "0.0" android:duration = "300" /> </ set > |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_31715429/article/details/50972357