zoukankan      html  css  js  c++  java
  • ViewFlipper实现自动播放的图片库

    作者实现的基础上,加上了文字的变换

    1. public class MainActivity extends Activity
    2. {
    3. private ViewFlipper viewFlipper;
    4. private Button autoplay;
    5. @Override
    6. public void onCreate(Bundle savedInstanceState)
    7. {
    8. super.onCreate(savedInstanceState);
    9. setContentView(R.layout.main);
    10. viewFlipper = (ViewFlipper) findViewById(R.id.details);
    11. autoplay = (Button) findViewById(R.id.autoplay);
    12. }
    13. public void prev(View source)
    14. {
    15. viewFlipper.setInAnimation(this , R.anim.slide_in_right);
    16. viewFlipper.setOutAnimation(this , R.anim.slide_out_left);
    17. // 显示上一个组件
    18. viewFlipper.showPrevious();
    19. // 停止自动播放
    20. viewFlipper.stopFlipping();
    21. autoplay.setText("自动播放");
    22. }
    23. public void next(View source)
    24. {
    25. viewFlipper.setInAnimation(this , android.R.anim.slide_in_left);
    26. viewFlipper.setOutAnimation(this , android.R.anim.slide_out_right);
    27. // 显示下一个组件
    28. viewFlipper.showNext();
    29. // 停止自动播放
    30. viewFlipper.stopFlipping();
    31. autoplay.setText("自动播放");
    32. }
    33. public void auto(View source)
    34. {
    35. viewFlipper.setInAnimation(this , android.R.anim.slide_in_left);
    36. viewFlipper.setOutAnimation(this , android.R.anim.slide_out_right);
    37. String s=autoplay.getText().toString();
    38. if (s.equals("自动播放")) {
    39. // 开始自动播放
    40. viewFlipper.startFlipping();
    41. autoplay.setText("停止自动");
    42. } else {
    43. viewFlipper.stopFlipping();
    44. autoplay.setText("自动播放");
    45. }
    46.  
    47. }
    48. }

    XML文件

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <RelativeLayout
    3. xmlns:android="http://schemas.android.com/apk/res/android"
    4. android:layout_width="match_parent"
    5. android:layout_height="match_parent">
    6. <ViewFlipper
    7. android:id="@+id/details"
    8. android:layout_width="match_parent"
    9. android:layout_height="match_parent"
    10. android:flipInterval="1000">
    11. <ImageView
    12. android:src="@drawable/java"
    13. android:layout_width="match_parent"
    14. android:layout_height="wrap_content">
    15. </ImageView>
    16. <ImageView
    17. android:src="@drawable/android"
    18. android:layout_width="match_parent"
    19. android:layout_height="wrap_content">
    20. </ImageView>
    21. <ImageView
    22. android:src="@drawable/javaee"
    23. android:layout_width="match_parent"
    24. android:layout_height="wrap_content">
    25. </ImageView>
    26. </ViewFlipper>
    27. <Button
    28. android:text="<"
    29. android:onClick="prev"
    30. android:layout_width="wrap_content"
    31. android:layout_height="wrap_content"
    32. android:layout_alignParentBottom="true"
    33. android:layout_alignParentLeft="true"/>
    34. <Button
    35. android:id="@+id/autoplay"
    36. android:layout_width="wrap_content"
    37. android:layout_height="wrap_content"
    38. android:layout_alignParentBottom="true"
    39. android:layout_centerInParent="true"
    40. android:onClick="auto"
    41. android:text="自动播放"/>
    42. <Button
    43. android:text=">"
    44. android:onClick="next"
    45. android:layout_width="wrap_content"
    46. android:layout_height="wrap_content"
    47. android:layout_alignParentBottom="true"
    48. android:layout_alignParentRight="true"/>
    49. </RelativeLayout>
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <set xmlns:android="http://schemas.android.com/apk/res/android">
    3. <!-- 设置从右边拖进来的动画
    4. android:duration指定动画持续时间 -->
    5. <translate
    6. android:fromXDelta="100%p"
    7. android:toXDelta="0"
    8. android:duration="@android:integer/config_mediumAnimTime" />
    9. </set>
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <set xmlns:android="http://schemas.android.com/apk/res/android">
    3. <!-- 设置从左边拖出去的动画
    4. android:duration指定动画持续时间 -->
    5. <translate
    6. android:fromXDelta="0"
    7. android:toXDelta="-100%p"
    8. android:duration="@android:integer/config_mediumAnimTime" />
    9. </set>

    效果

  • 相关阅读:
    AD7606笔记
    转Keil 中使用 STM32F4xx 硬件浮点单元
    旋转编码器
    PT100/PT1000
    电压跟随器
    段式液晶驱动方法
    物联网的架构
    物联网的操作系统
    C8051开发环境
    解决time命令输出信息的重定向问题
  • 原文地址:https://www.cnblogs.com/wwjldm/p/6930514.html
Copyright © 2011-2022 走看看