Android ApiDemos示例解析(97):Views->Animation->Push
2012-08-01 09:08
429 查看
在例子Android ApiDemos示例解析(95):View->Animation->3D Transition 为了在FrameLayout切换两个View :ListView 和 ImageView, 需要编写很多代码来实现两个View之间的切换。
Android 其实提供了一个更为简便的类ViewFlipper ,ViewFlipper既是FrameLayout 的子类,又是ViewAnimator 的子类,因此在功能上ViewFlipper 和FrameLayout类似,但它可以自动管理包含在ViewFlipper在各个子类之间的切换,而View之间的切换的动画效果可以通过ViewAnimator的功能来实现。
ViewAnimator 运行定义两个Animation动作:
inAnimation: 当View显示时动画资源ID
outAnimation: 当View隐藏是动画资源ID。
ViewFlipper 自动切换包含在其中的View,同一时间只能显示一个View,在View之间切换时,以inAnimation 动画显示新出现的View,而以outAnimation 动画隐藏先前的View。
本例中ViewFlipper 中定义了四个TextView,每个TextView显示一行文字:
调用ViewFlipper 的 startFlipping() 开始以相同的间隔顺序显示四个TextView。
提供一个Spinner(下拉框)允许设置不同inAnimation 和outAnimation 为TextView显示隐藏添加不同的动画效果,如:左边出左边进
Android 其实提供了一个更为简便的类ViewFlipper ,ViewFlipper既是FrameLayout 的子类,又是ViewAnimator 的子类,因此在功能上ViewFlipper 和FrameLayout类似,但它可以自动管理包含在ViewFlipper在各个子类之间的切换,而View之间的切换的动画效果可以通过ViewAnimator的功能来实现。
ViewAnimator 运行定义两个Animation动作:
inAnimation: 当View显示时动画资源ID
outAnimation: 当View隐藏是动画资源ID。
ViewFlipper 自动切换包含在其中的View,同一时间只能显示一个View,在View之间切换时,以inAnimation 动画显示新出现的View,而以outAnimation 动画隐藏先前的View。
本例中ViewFlipper 中定义了四个TextView,每个TextView显示一行文字:
<ViewFlipper android:id=”@+id/flipper” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:flipInterval=”2000″ android:layout_marginBottom=”20dip” > <TextView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:gravity=”center_horizontal” android:textSize=”26sp” android:text=”@string/animation_2_text_1″/> <TextView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:gravity=”center_horizontal” android:textSize=”26sp” android:text=”@string/animation_2_text_2″/> <TextView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:gravity=”center_horizontal” android:textSize=”26sp” android:text=”@string/animation_2_text_3″/> <TextView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:gravity=”center_horizontal” android:textSize=”26sp” android:text=”@string/animation_2_text_4″/> </ViewFlipper>
调用ViewFlipper 的 startFlipping() 开始以相同的间隔顺序显示四个TextView。
mFlipper.startFlipping();
提供一个Spinner(下拉框)允许设置不同inAnimation 和outAnimation 为TextView显示隐藏添加不同的动画效果,如:左边出左边进
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in)); mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
相关文章推荐
- Android ApiDemos示例解析(98):Views->Animation->Shake
- Android ApiDemos示例解析(95):Views->Animation->3D Transition
- Android ApiDemos示例解析(96):Views->Animation->Interpolators
- Android ApiDemos示例解析(183):Views->Progress Bar->2. Smooth
- Android ApiDemos示例解析(109):Views->Custom
- Android ApiDemos示例解析(148):Views->Layouts->LinearLayout->8. Gravity
- Android ApiDemos示例解析(103):Views->Auto Complete->5. Contacts with Hint
- Android ApiDemos示例解析(189):Views->ScrollBars->2.Fancy
- Android ApiDemos示例解析(109):Views->Custom
- Android ApiDemos示例解析(191):Views->Seek Bar
- Android ApiDemos示例解析(170):Views->Lists->3. Cursor (Phones)
- Android ApiDemos示例解析(104):Views->Auto Complete->6. Multiple Items
- Android ApiDemos示例解析(151):Views->Layouts->RelativeLayout->1. Vertical
- Android ApiDemos示例解析(112):Views->Expandable Lists->1. Custom Adapter
- Android ApiDemos示例解析(113):Views->Expandable Lists->2. Cursor(People)
- Android ApiDemos示例解析(178):Views->Lists->11. Multiple choice list
- Android ApiDemos示例解析(182):Views->Progress Bar->1. Incremental
- Android ApiDemos示例解析(185):Views->Progress Bar->4. In Title Bar
- Android ApiDemos示例解析(158):Views->Layouts->TableLayout->03.Long Content
- Android ApiDemos示例解析(114):Views->Expandable Lists->3. SimpleAdapter