Android

Binary XML file line #2: invalid drawable tag oneshot

Fatal Exception: java.lang.RuntimeException

Unable to start activity ComponentInfo{com.ment/com.ment.StatusActivity}: android.view.InflateException: Binary XML file line #57: Error inflating class android.widget.ImageView
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2118)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2143)
android.app.ActivityThread.access$700 (ActivityThread.java:140)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1237)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loop (Looper.java:174)
android.app.ActivityThread.main (ActivityThread.java:4952)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1027)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:794)
dalvik.system.NativeStart.main (NativeStart.java)

xml파일 57번째 라인의 ImageView에서 오류가 발생했음을 알려준다.

백그라운드에 사용된  xml파일이 문제가 되었던 것이다.


<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/musicLayout"
android:layout_below="@+id/ttsTextView"
android:gravity="center|center_vertical"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgViewMotion"
android:background="@drawable/music_motion_list" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/musicTxt"
android:textColor="#a4a4a4"
android:textSize="16sp"
android:layout_marginLeft="15dp" />
</LinearLayout>



xml파일의 2번째 라인에 잘모된 tag가 사용되어 오류가 발생하였다.
music_motion_list.xml 


<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/motion_gray1" android:duration="300" />
<item android:drawable="@drawable/motion_gray2" android:duration="300" />
<item android:drawable="@drawable/motion_gray3" android:duration="300" />
</animation-list>

3개의 프레임으로 애니메이션을 만들었고 android:oneshot="false"를 설정하여 에니메이션 반복을 설정하였다.

그런데 이게 왜 문제가 되는 것인가? 

개발자 가이드 문서에도 떡하니 사용법까지 나온 태그이다.
https://developer.android.com/guide/topics/graphics/drawable-animation.html

그래서 문뜩 생각하나가 스친다.

oneshot의 디폴트값이 만약에 false라면 굳이 명시적으로 사용할 필요는 없겠구나..

바로 테스트에 들어갔다. 확인결과 디폴트값은 false 였다.

명시적으로 사용했던 oneshot 태그를 삭제하였다.

Leave a Reply

error: Content is protected !!