首页 > 代码库 > 帧动画

帧动画

技术分享

main.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        ImageView mv=(ImageView) findViewById(R.id.imageView1);
        AnimationDrawable drawable = (AnimationDrawable) mv.getBackground();
        drawable.start();

    }
}

2. main.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="myapplication.com.mydonghua.MainActivity">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="122dp"
        android:layout_marginTop="183dp"
        android:background="@drawable/load" />

</RelativeLayout>

<!-------------------------->

drawable下的animation_list

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@mipmap/loading_0"
        android:duration="100"/>
    <item
        android:drawable="@mipmap/loading_1"
        android:duration="100"/>
    <item
        android:drawable="@mipmap/loading_2"
        android:duration="100"/>
    <item
        android:drawable="@mipmap/loading_3"
        android:duration="100"/>
    <item
        android:drawable="@mipmap/loading_4"
        android:duration="100"/>
    <item
        android:drawable="@mipmap/loading_5"
        android:duration="100"/>
    <item
        android:drawable="@mipmap/loading_6"
        android:duration="100"/>
    <item
        android:drawable="@mipmap/loading_7"
        android:duration="100"/>
</animation-list>

 

帧动画