안드로이드

 

class MainActivity

 

package kr.co.braverokmc.myframeanimation;

import android.content.res.Resources;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    ImageView imageView;
    AnimationDrawable drawable;

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

        imageView=(ImageView)findViewById(R.id.imageView);

        Resources res =getResources();
        Drawable frame1 =res.getDrawable(R.drawable.a1);
        Drawable frame2 =res.getDrawable(R.drawable.a2);
        Drawable frame3 =res.getDrawable(R.drawable.a3);
        Drawable frame4 =res.getDrawable(R.drawable.a4);

        int duration=500;
        drawable=new AnimationDrawable();
        drawable.addFrame(frame1, duration);
        drawable.addFrame(frame2, duration);
        drawable.addFrame(frame3, duration);
        drawable.addFrame(frame4, duration);
        drawable.setOneShot(false);

    }



    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public void onClick(View v){
        imageView.setBackground(drawable);

        drawable.setVisible(true, true);
        drawable.start();
    }




}







 

 

R.layout.activity_main

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    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="kr.co.braverokmc.myframeanimation.MainActivity">

    <Button
        android:text="시작"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="117dp"
        android:layout_marginStart="117dp"
        android:id="@+id/button"
        android:onClick="onClick"
        />

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="48dp"
        android:id="@+id/imageView"
        android:layout_below="@+id/button"
        android:layout_alignLeft="@+id/button"
        android:layout_alignStart="@+id/button" />


</RelativeLayout>







 

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

절에 가면 중 노릇 하고 싶다 , 줏대나 지조가 없이 남이 하는 일을 보면 덮어놓고 따르려고 한다는 말.

댓글 ( 4)

댓글 남기기

작성