当前位置: 首页 > 知识库问答 >
问题:

膨胀 Mvx.MvxImageView 时出错

谷梁凌
2023-03-14

我在自定义控件中膨胀MvxImageView时遇到问题。

从我所做的研究中,我发现了几个嫌疑人

> < li >我是否应该将“如果”添加到“什么”中?(我看到这是关于android地图视图膨胀错误。 < li>

我创建的用户控件是不是都错了?我看到了一个使用SetContentView()而不是inflate的建议,因为它通过mvvmcross机制传递indlate请求,但在自定义视图中没有这样的方法。

这是自定义控件布局:

<?xml version="1.0" encoding="utf-8"?>    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:local="http://schemas.android.com/apk/res/Com.TasteITAndroidClient"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" >
<Mvx.MvxImageView android:scaleType="centerCrop"
                  android:id="@+id/Image"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" />

下面是用户控件实现:

public class UserControl : LinearLayout
{
    public UserControl(Context context, IAttributeSet attrs) : base(context,attrs)
    {
        LayoutInflater inflater = LayoutInflater.From(context);
        inflater.Inflate (Resource.Layout.UserControl, this);
    }
}

这是我使用它的地方:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
    android:id="@+id/myButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />
    <TestApp.UserControl 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

我收到以下异常:

Android视图。InflateException:二进制XML文件行#1:扩展类Mvx时出错。Android.Runtime.JNIEnv上的MvxImageView。Android.Views.LayoutInfluer上的/Users/builder/data/lanes/mondroid-mlion-mondroid-4.8.0-branch/9486a4ec/source/mondroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:145中的CallObjectMethod(intptr、intptr,Android.Runtime.JValue[])[0x00024]。在/Users/builder/data/lanes/mondroid-mlion-mondroid-4.8.0-branch/9486a4ec/source/monodroid/src/Mono.Android/platforms/Android-8/src/generated/Android.Views.LayoutInflater中充气(int,Android.Views.ViewGroup)[0x00043]。cs:422位于c:\Users\Amit\Documents\Projects\TestApp\TestApp\测试App\TestApp \UserControl中的TestApp.UserControl..ctor(Android.Content.Context,Android.Util.IAttributeSet)[0x00011]。cs:20at(包装动态方法)对象。bd915d4e-f205-49cd-a1e8-a0532b2db313(intptr,object[]),位于Java.Interop.TypeManager。n_Activate(intptr,intptr、intptr和intptr)[0x00070]位于/Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/9486a4ec/source/mondroid/src/Mono.Android/src/Java.Interop/TypeManager中。cs:141位于(托管的本地包装器)Java.Interop.TypeManager。n_Activate(intptr,intptr、intptr和intptr)at(包装器管理为本机)对象。wrapper_native_0x40819b9d(intptr、intptr和intptr,Android.Runtime.JValue[])

共有1个答案

安坚诚
2023-03-14

我对你正在做的事情感到困惑——你似乎试图在一个非数据绑定的环境中膨胀数据绑定的对象。

这两个关于使用子控件的教程可能会有所帮助:

>

  • 在 MvvmCross 中编写自定义 Android 控件在 N=18 中介绍了 https://mvvmcross.wordpress.com/

    使用片段,MvvmCross中的MvxFrameControl包含在N=26英寸https://mvvmcross.wordpress.com/

    或者,由于您的布局没有自定义功能-它只是XML-那么您可以考虑只使用Android<code>

  •  类似资料:
    • 我试图将我的GLSurfaceView设置在xml布局以及其他UI元素上,并不断获得错误inflating类com.vi.cubo01。MyGLSurfaceView在LogCat. 以下是java代码: 以及xml:

    • 问题内容: 您好,我是android dev和admob的新手。我正在尝试制作一个带有按钮,几个页面和底部的admob的简单测试应用程序。一切正常,直到我尝试实施admob。这是我的代码: HelloAndroid.java: main.xml: 您好android清单: logcat输出: 我正在使用GoogleAdMobAdsSdkAndroid-6.0.0。再次,我对此非常陌生,我尝试在多个

    • 问题内容: 错误日志: 10-26 12:22:33.144 26926-26926 /?E / AndroidRuntime:致命例外:主进程:ksmk.sahip.com.ecom,PID:26926 java.lang.RuntimeException:无法启动活动ComponentInfo {ksmk.sahip.com.ecom / ksmk.sahip.com.ecom.MainAct

    • 我在三星SM G920F(Galaxy S6)5.1.1版中发现了Crashlytics的崩溃报告(在所有其他设备上,我没有检索到相同的错误)。 这是我的网络视图的布局(样式为空样式): 以下是我如何将其包括在活动布局中: 报告的错误是XML错误,所以我提供了所有代码(简化)。这是一个单一的报告,所以它只在这个设备上发生过一次,有人能解释一下为什么吗? 编辑(完成堆栈跟踪)

    • 问题内容: 尝试运行我的应用程序时,我意外地遇到了以下错误: 下面是日志猫: 以下是Java代码: 下面是布局代码: 提前致谢 问题答案: 我通过在app / build.gradle上添加更新的cardview和appcompat解决了这一问题 然后重建项目

    • 问题内容: 我正在尝试创建一个扩展的自定义视图。这是我的班级定义文件 : 这是在我的ghostviewscreen.xml中: 现在,我在活动中进行了: 当被调用时,抛出一个异常: 谁能告诉我为什么会出现此错误?谢谢。 问题答案: 我想我弄清楚了为什么这没用。当我应该为两个参数“ Context,AttributeSet”的情况提供构造函数时,我只为一个参数“ context”的情况提供了构造函数