zoukankan      html  css  js  c++  java
  • android 多张图片动画方式轮播(转载)

    /res/drawable/flag.xml

    <?xml version="1.0" encoding="utf-8"?>
    <animation-list     
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/flaganim"
        android:oneshot="false"
        >
    <!--android:duration="xxx"控制该图片显示时间长度-->
        <item android:drawable="@drawable/f03" android:duration="100" />
        <item android:drawable="@drawable/f04" android:duration="100" />
        <item android:drawable="@drawable/f05" android:duration="100" />
        <item android:drawable="@drawable/f06" android:duration="100" />
        <item android:drawable="@drawable/f07" android:duration="100" />
        <item android:drawable="@drawable/f08" android:duration="100" />
        <item android:drawable="@drawable/f09" android:duration="100" />
        <item android:drawable="@drawable/f10" android:duration="100" />    
    </animation-list>

    /res/layout/splash.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" 
      android:id="@+id/TheSplashLayout"
      android:layout_gravity="center"
      >
        <ImageView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/SplashImageView"
            android:layout_gravity="center"        
            >
        </ImageView>
        <!-- 
        Not animated
        <ImageView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/SplashImageView"
            android:src="http://blog.163.com/hero_213/blog/@drawable/lnxins"
            android:layout_gravity="center"        
            >
         -->
    </LinearLayout>

    MainActivity.java

    final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
            splashImageView.setBackgroundResource(R.drawable.flag);
            final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
            splashImageView.post(new Runnable(){
                @Override
                public void run() {
                    frameAnimation.start();//启动动画
                // frameAnimation.stop(); //关闭动画
                }            
            });
     

    除此之外:在AnimationDrawable中,我们还可以看到如下的几个重要方法:

    setOneShot(boolean flag) 和在配置文件中进行配置一样,可以设置动画是否播放一次,false为连续播放;

    addFrame (Drawable frame, int duration) 动态的添加一个图片进入该动画中

                              作者:xubuhang                出处:http://www.cnblogs.com/xubuhang/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 

     
查看全文
  • 相关阅读:
    ASP.NET- 查找Repeater控件中嵌套的控件
    Oracle- 表的管理
    Oracle- PL/SQL DEV工具的使用收集
    Oracle- PL/SQL DEV的远程配置
    Oracle- 提示查询结果不可更新,请使用...更新结果。
    Oracle- 存储过程和异常捕捉
    MSSQLSERVER数据库- SP_EXECUTESQL的使用
    Oracle- 用户管理
    Oracle- 初识
    c语言交换两个变量的值
  • 原文地址:https://www.cnblogs.com/xubuhang/p/4223502.html
  • Copyright © 2011-2022 走看看