一、简介


    ViewSwitcher适用于两个视图带动画效果的切换。这里实现两个视图切换的功能,并附带滑屏效果。

  二、截图

二、范例代码


    带动画效果的切换视图一和视图二。

    xml

<ViewSwitcher android:layout_alignParentBottom="true"
android:persistentDrawingCache="animation" android:id="@+id/bottom"
android:layout_width="match_parent" android:inAnimation="@android:anim/slide_in_left"
android:outAnimation="@android:anim/slide_out_right" android:layout_height="122.0dip">
<RelativeLayout android:layout_width="fill_parent"
android:layout_gravity="bottom" android:layout_marginBottom="12.0dip"
android:id="@+id/lyBottom" android:layout_height="wrap_content">
<Button android:id="@+id/btn_pre" android:text="上一步"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toLeftOf="@+id/btn_middle"
android:layout_marginRight="150.0dip" />
<Button android:id="@+id/btn_middle" android:layout_width="wrap_content"
android:layout_centerInParent="true" android:onClick="onClick" android:visibility="invisible"
android:textSize="22.0sp"
android:layout_height="wrap_content"></Button>
<Button android:id="@+id/btn_next" android:text="下一步"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toRightOf="@+id/btn_middle"
android:layout_marginLeft="150.0dip" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_gravity="bottom" android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:src="@drawable/cube" android:id="@+id/btn_reinsure"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="150.0dip"></ImageView>
<ImageView android:src="@drawable/cyddz" android:id="@+id/btn_identity"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn_reinsure"
android:layout_marginLeft="124.0dip"></ImageView>
<ImageView android:src="@drawable/cykvmce" android:id="@+id/btn_insure_query"
android:layout_toRightOf="@+id/btn_identity" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="140.0dip"></ImageView>
<ImageView android:src="@drawable/m8gprs" android:id="@+id/btn_review"
android:layout_toRightOf="@+id/btn_insure_query"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="140.0dip"></ImageView>
<ImageView android:src="@drawable/th_appshareth"
android:layout_toRightOf="@+id/btn_review"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="130.0dip"></ImageView>
</RelativeLayout>
</ViewSwitcher>


代码说明:

        1. 这里使用系统自带的切换效果@android:anim/slide_in_left和@android:anim/slide_out_right。

        2. 请大家自行准备测试图片

    java
bottom = (ViewSwitcher) findViewById(R.id.bottom);
//切换为第一个
bottom.setDisplayedChild(0);
//切换到下一个
//bottom.showNext()

更多相关文章

  1. android 仿京东抢购上下轮播消息
  2. android 屏幕切换
  3. Android之实现上下左右翻页效果
  4. Android中View的绘制流程详解
  5. gradle切换为阿里云镜像
  6. android 实现自动输入文本效果
  7. Android(安卓)---- 侧滑删除菜单的实现
  8. Android简单实现 高德地图的定位与显示,点击按钮切换地图图层
  9. Android(安卓)ViewPager用法

随机推荐

  1. Android 和 PHP 之间进行数据加密传输
  2. Android的第一个程序运行
  3. 在Android中解析XML
  4. Android(安卓)2.3.x WebView中的两个搞笑
  5. Lottie-移动动画效果框架
  6. Android(安卓)NDK简介
  7. android camera 布局分析
  8. android上传图片到服务器,求服务器那边和a
  9. 对Android(安卓)ListView的理解
  10. Android界面与交互设计原则