[功能]
1. ViewFlipper 可以包含多个View 且View之间的切换有Animation 比如:渐变效果


[代码]
1. 创建包含ViewFlipper 的main.xml 还包含2个Button 用于各个View切换

Java代码
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  8. android:orientation="horizontal"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. >
  12. <Button
  13. android:id="@+id/previousButton"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:text="Previous"
  17. />
  18. <Button
  19. android:id="@+id/nextButton"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:text="Next"
  23. />
  24. </LinearLayout>
  25. <ViewFlipper
  26. android:id="@+id/flipper"
  27. android:layout_width="fill_parent"
  28. android:layout_height="fill_parent"
  29. android:gravity="center"
  30. >
  31. </ViewFlipper>
  32. </LinearLayout>



2. 设定 Animation 效果

Java代码
  1. flipper=(ViewFlipper)findViewById(R.id.flipper);
  2. flipper.setInAnimation(AnimationUtils.loadAnimation(this,
  3. android.R.anim.fade_in));
  4. flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
  5. android.R.anim.fade_out));



3. 在 ViewFlipper 里面增加各种View

Java代码
  1. flipper.addView(addTextByText("HelloAndroid"));
  2. flipper.addView(addImageById(R.drawable.beijing_003_mb5ucom));
  3. flipper.addView(addTextByText("eoe.Android"));
  4. flipper.addView(addImageById(R.drawable.beijing_004_mb5ucom));
  5. flipper.addView(addTextByText("Gryphone"));
  6. ublicViewaddTextByText(Stringtext){
  7. TextViewtv=newTextView(this);
  8. tv.setText(text);
  9. tv.setGravity(1);
  10. returntv;
  11. }
  12. publicViewaddImageById(intid){
  13. ImageViewiv=newImageView(this);
  14. iv.setImageResource(id);
  15. returniv;
  16. }




4. View 切换
* 下一个View

Java代码
  1. flipper.showNext();



* 上一个View

Java代码
  1. flipper.showPrevious();




现释出所有代码!

over.

  • MyFlipperUsage.rar (142.6 KB)
  • 下载次数: 48

更多相关文章

  1. Andorid TabHost 使用小结
  2. Android(安卓)GridView控件 使用
  3. Android资料(书籍+代码)
  4. android 横竖屏切换,activity的生命周期
  5. 完美PopupWindow(记住用户名模拟)
  6. fragment内嵌fragment之间传值+切换fragment
  7. android Tween Animations(动画效果-代码实现)的使用
  8. Android获取手机屏幕宽高、状态栏高度以及字符串宽高信息的方法
  9. [置顶] android 框架

随机推荐

  1. Android教程之实现动作感应技术
  2. android内容提供者ContentProvider,UriMa
  3. android apk 怎么执行adb shell命令
  4. android include merge标签
  5. Android MediaPlayer使用之网络访问异常
  6. Linux, Android电源管理:wakelock,autoslee
  7. Android 录音(录音时为pcm,然后转为MP3)
  8. Android(安卓)Gesture 手势识别使用实例
  9. android 测试读取LEB数据的函数
  10. Android 实现文件的下载