搜索
您的当前位置:首页正文

Andriod中的动画

来源:二三娱乐

1、帧动画

加载一系列的图片,形成动画

drawable下的xml文件

<?xml version="1.0" encoding="utf-8"?>
<animation-list 
    android:oneshot="false">
    <item
        android:drawable="@drawable/tou1"
        android:duration="200" />

    <item
        android:drawable="@drawable/touxiang1"
        android:duration="200" />
    <item
        android:drawable="@drawable/z"
        android:duration="200" />

</animation-list>

主函数

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //找到imageview
        final ImageView iv =(ImageView) findViewById(R.id.iv);
        //加载图片资源
        iv.setBackgroundResource(R.drawable.my_anima);

        //兼容低版本的写法
//        new Thread(){
//            @Override
//            public void run() {
//                SystemClock.sleep(20);
//                //获取Animatable
//                Animatable animatable =(Animatable)iv.getBackground();
//                //开启
//                animatable.start();
//            }
//        }.start();

        //获取Animatable
        Animatable animatable =(Animatable)iv.getBackground();
       //开启
        animatable.start();
    }
}
Top