看到一个程序员笔记里,有几句标语使用的是自动切换的模式,开始还以为做的是动画,看了源码才知道,使用的是ViewFlipper,在开发文档里,说的是简单的ViewAnimator,使你添加的View动起来,在同一个时间只有一个View被展示出来,也可以设定好几个View轮流展示。

注意几个特别的设置就可以使用,android:flipInterval="2000",设置里面每一个View显示的时间,startFlipping()启动自动滑动过程,stopFlipping()停止自动化过程。

下边我把程序里的语句摘出来,单独写了个测试的应用。在.xml里面使用ViewFlipper,在ViewFlipper里面包含几个TextView,代码如下:

<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" >    <ViewFlipper        android:id="@+id/flipper"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_alignParentTop="true"        android:layout_marginTop="10dp"        android:flipInterval="2000" >        <TextView            android:id="@+id/text_1"            style="@style/edittext_shadow_style"            android:text="@string/animation_2_text_1" />        <TextView            android:id="@+id/text_2"            style="@style/edittext_shadow_style"            android:text="@string/animation_2_text_2" />        <TextView            android:id="@+id/text_3"            style="@style/edittext_shadow_style"            android:text="@string/animation_2_text_3" />        <TextView            android:id="@+id/text_4"            style="@style/edittext_shadow_style"            android:text="@string/animation_2_text_4" />    </ViewFlipper></RelativeLayout>

然后再MainActivity里面直接找到ViewFlipper,启动就可以,代码:

    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        flipper = (ViewFlipper) findViewById(R.id.flipper);flipper.startFlipping();    }

然后就可以看到,ViewFlipper里面四个空间轮流显示的过程了。

代码:点我下载

更多相关文章

  1. android中网络操作使用总结(http)
  2. android test 和 instrumentation
  3. Android服务注册完整过程源码分析
  4. android键盘隐藏
  5. 如何在android 中编译alsa-utils工具
  6. Android(安卓)Webview 基本使用总结
  7. Android自定义属性时TypedArray的使用方法
  8. Android应用程序签名验证过程分析
  9. Android中资源文件的使用

随机推荐

  1. Android编译系统(四):Android 编译系统框
  2. Android多进程之Binder解绑监听的问题
  3. Android图形显示系统——下层显示3:窗口系
  4. Android硬件控制之USB连接
  5. 如何学习android
  6. Android中资源文件的Shape使用总结
  7. 跟着做 Android NDK学习入门如此简单(一)
  8. Android一日游
  9. android布局文件中各属性所代表的意义
  10. Android 控件布局常用属性