Android 프레임 애니메이션 생 성 실례 상세 설명

Android 프레임 애니메이션 생 성 실례 상세 설명
선언:
우리 가 초기 영 화 를 볼 때 영 화 는 보통 한 장의 재생 이 었 다.우리 가 현재 가지 고 있 는 고유 명사 로 볼 때 바로 프레임 이 었 다.안 드 로 이 드 역시 이런 애니메이션 효과 의 편성 형식 을 가지 고 있다.
그러면 우 리 는 먼저 프레임 애니메이션 xml 파일 을 정의 합 니 다.

<?xml version="1.0" encoding="utf-8"?> 
<animation-list 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:oneshot="true"> 
 
  <item 
    android:drawable="@drawable/pic1" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic2" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic3" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic4" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic5" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic6" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic7" 
    android:duration="200" /> 
   <item 
    android:drawable="@drawable/pic8" 
    android:duration="200" /> 
   <item 
    android:drawable="@drawable/pic8" 
    android:duration="200" /> 
    
 
 
</animation-list> 
main.xml

<ImageView 
    android:id="@+id/pic" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="98dp" 
    android:layout_marginTop="69dp" 
     /> 
 
  <Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginBottom="54dp" 
    android:layout_marginLeft="98dp" 
    android:onClick="startMovie" 
    android:text="      " /> 
 
Activity 코드:

public class MyAnimationDemo extends Activity { 
 
  private AnimationDrawable draw=null; 
  private ImageView image; 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_my_animation_demo); 
    image=(ImageView)super.findViewById(R.id.pic); 
  } 
 
  public void startMovie(View v){ 
    image.setBackgroundResource(R.anim.oldvideo);//   ,       
    draw=(AnimationDrawable)image.getBackground();//       Drawable 
    draw.setOneShot(false);//       
    draw.start();//     
     
  } 
 
} 
 
여기 우리 가 봤 는데,
첫 번 째,그림 배경 자원 설정
두 번 째 단 계 는 그림 배경 을 가 진 draw 를 설정 합 니 다.
세 번 째 단계,draw 인 자 를 설정 하고 start()
실현 효 과 는 다음 과 같다.0.2 초 간격 으로 그림 을 바 꾸 고 오래된 영화 애니메이션 효 과 를 실현 한다.



 
 이상 은 바로 안 드 로 이 드 프레임 애니메이션 의 사례 상세 한 설명 입 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남기 거나 본 사이트 지역사회 에 가서 토론 을 하 십시오.읽 어 주 셔 서 감사합니다. 여러분 께 도움 이 되 기 를 바 랍 니 다.본 사이트 에 대한 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기