Android.Views.InflateException:二进制XML文件行#1:二进制XML文件行#1:错误膨胀类android.widget.ImageView

时间:2017-05-02 12:39:07

标签: c# android xml xamarin xamarin.android

我试图找到解决方案差不多一个星期。有人可以帮忙解决这个错误吗?当我构建它时,我没有错误。调试时当然会抛出异常。这就是我得到的 - >

" Android.Views.InflateException:二进制XML文件行#1:二进制XML文件行#1:错误膨胀类android.widget.ImageView"。

所以似乎问题是视图无法设置(我不知道为什么),即使我使用了与此处所示相同的示例 - > https://developer.xamarin.com/recipes/android/other_ux/animation/frame_animation/进行了微小的更改(我的动画列表不在"资源 - > Anim"文件夹,但它在"资源 - > drawable"文件夹和我不要使用动画启动" OnFocus")。首先,这是我的Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <ImageView
        android:id="@+id/animatedscreen1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/FirstScreenAnimated" />
</LinearLayout>

其次,这是我的&#34; FirstScreenAnimated.xml&#34;我有动画列表的图像。

<?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/BoyIntro01"
        android:duration="80"  />
  <item android:drawable="@drawable/BoyIntro02"
        android:duration="80"  />
  <item android:drawable="@drawable/BoyIntro03"
        android:duration="80"  />
  <item android:drawable="@drawable/BoyIntro04"
        android:duration="80" />
  <item android:drawable="@drawable/BoyIntro05"
        android:duration="80" />
</animation-list>

最后,这是我的&#34; FirstActivity.cs&#34;我在SplashScreen之后尝试启动动画的地方:

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using ListViewSwipeItem;
using System.Threading;
using Android.Graphics.Drawables;
using Android.Support.V7.App;

namespace LiveBookIntro
{
    [Activity (Label = "Step 1")]
    public class FirstActivity : Activity
    {
        GestureDetector _gestureDetector;
        GestureListener _gestureListener;

        public object NavigationPage { get; private set; }

        ImageView imageView;
        AnimationDrawable animation;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main); //This is the line where I get the exception! 
            imageView = FindViewById<ImageView>(Resource.Id.animatedscreen1);
            animation = (AnimationDrawable)imageView.Drawable;

            imageView.Clickable = true;
            imageView.Click += ImageView_Click;

            _gestureListener = new GestureListener();
            _gestureListener.LeftEvent += GestureLeft;
            _gestureListener.RightEvent += GestureRight;
            _gestureDetector = new GestureDetector(this, _gestureListener);

            void GestureLeft()
            {
                StartActivity(typeof(SecondActivity));
            }

            void GestureRight()
            {
                //nothing
            }

        }

        private void ImageView_Click(object sender, System.EventArgs e)
        {
            if (!animation.IsRunning)
            {
                animation.Start();
            }
            else
            {
                animation.Stop();
            }
        }

        public override bool DispatchTouchEvent(MotionEvent ev)
        {
            _gestureDetector.OnTouchEvent(ev);
            return base.DispatchTouchEvent(ev);
        }
    }
}

正如我所提到的,我尝试用google和我自己解决它,但我不能......所以任何帮助都会很棒!如果您需要更多信息,我会尽快回复。

1 个答案:

答案 0 :(得分:0)

这一行

android:src="@drawable/FirstScreenAnimated" />

必须是

android:src="@anim/FirstScreenAnimated"