Android自定义动画导致InflateException

时间:2015-08-18 12:25:20

标签: android android-animation

所以,我创建了一个xml动画:

view_slider.xml :

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:duration="500"
    android:fromYDelta="100%"
    android:toYDelta="0%"
    >

</translate>

现在我在我的一个布局中使用它:

   Other Layout :

   <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:emoticon="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:foreground="@color/transparent"
        android:layoutAnimation="@anim/**view_slider**"
         >

        <RelativeLayout
            android:id="@+id/vox_full_content_relativeLayout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@drawable/voxpop_background"
            android:padding="5dp" >
            .......
            .......

应用程序崩溃了这个堆栈:

08-18 17:34:54.180: E/AndroidRuntime(25482): FATAL EXCEPTION: main
08-18 17:34:54.180: E/AndroidRuntime(25482): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at com.jhamobi.yoapp.dashbaoard.Yo_local_msgs_list_fragment$VoxMsgItemsAdapter.getView(Yo_local_msgs_list_fragment.java:591)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.AbsListView.obtainView(AbsListView.java:2177)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.ListView.makeAndAddView(ListView.java:1840)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.ListView.fillDown(ListView.java:675)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.ListView.fillFromTop(ListView.java:736)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.ListView.layoutChildren(ListView.java:1655)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.AbsListView.onLayout(AbsListView.java:2012)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:907)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:493)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.View.layout(View.java:14296)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewGroup.layout(ViewGroup.java:4562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.Choreographer.doFrame(Choreographer.java:532)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.os.Handler.handleCallback(Handler.java:730)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.os.Looper.loop(Looper.java:137)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.app.ActivityThread.main(ActivityThread.java:5289)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at java.lang.reflect.Method.invokeNative(Native Method)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at java.lang.reflect.Method.invoke(Method.java:525)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at dalvik.system.NativeStart.main(Native Method)
08-18 17:34:54.180: E/AndroidRuntime(25482): Caused by: java.lang.reflect.InvocationTargetException
08-18 17:34:54.180: E/AndroidRuntime(25482):    at java.lang.reflect.Constructor.constructNative(Native Method)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-18 17:34:54.180: E/AndroidRuntime(25482):    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
08-18 17:34:54.180: E/AndroidRuntime(25482):    ... 57 more
08-18 17:34:54.180: E/AndroidRuntime(25482): Caused by: java.lang.RuntimeExcept

我使用带有列表视图的相同xml文件,此处的布局是该列表视图的项目。动画适用于列表视图。

另外,我正在使用appcompat v7库。

如果删除android:layoutanimation行,则代码正常。 我做错了什么?!

2 个答案:

答案 0 :(得分:0)

像这样使用,

Animation shake = AnimationUtils.loadAnimation(getActivity(), R.anim.view_slide);
                    getView().findViewById(R.id.review_store_type).startAnimation(shake);

不在XML内部。

答案 1 :(得分:0)

从xml中删除动画并添加&#34; @ + id / frameLayout&#34;你想要设置动画的FrameLayout,然后在你的代码中执行此操作:

FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
Animation viewSlider = AnimationUtils.loadAnimation(this, R.anim.view_slider);
frameLayout.startAnimation(viewSlider);