Resource.Layout.filename将返回错误的布局文件 [英] Resource.Layout.filename is returning the wrong layout file

查看:271
本文介绍了Resource.Layout.filename将返回错误的布局文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MonoDroid的应用程序项目(我们称之为 mainApp )。此引用 app.Screen 项目,这是一个MFA库项目。最初,我的活动是在 mainApp 项目。一切都工作正常。我需要放在 app.Screen 项目的一些活动(和资源,图形等)。
我提出我需要将 app.Screen 项目中的所有资源。它建立精细,在我的活动(这是坐在app.screens)我可以访问 Resource.Layout.filename ,甚至 Layout.Id.name

I have a MonoDroid application project (let's call it mainApp). This references app.Screen project, which is a MFA library project. Initially, my activities were in the mainApp project. Everything was working fine. I needed to put some Activities (and resource, drawables, etc) in the app.Screen project. I have moved all the resources I need to the app.Screen project. It builds fine and in my activities (which are sitting in app.screens) I can access Resource.Layout.filename and even Layout.Id.name.

然而,当我运行应用程序,在的setContentView(Resource.Layout.filename)我得到的错误的布局文件即可。这将导致 FindById<按钮>()返回很明显,因为它没有在这个布局文件这些按钮。

However, when I run the application, in SetContentView(Resource.Layout.filename) I get the wrong layout file . This causes FindById<Button>() to return null obviously because it does not have these buttons in this layout file.

我发现,相同的布局文件有不同的ID在我的MFA库项目比什么是在mainApp项目是这样的:

I found that same Layout file has different Id in my MFA library project than what is in the mainApp project like this:

// In the mainApp project
public partial class Layout
{
    // aapt resource value: 0x7f030001
    public const int DeliveryScreenLayout = 2130903041;

    // aapt resource value: 0x7f03000a
    public const int splash_screen_layout = 2130903050;

    private Layout()
    {
    }
}

// in app.screen library project
public partial class Layout
{

    // aapt resource value: 0x7f030000
    public static int has_hello_layout = 2130903040;

    // aapt resource value: 0x7f030001
    public static int splash_screen_layout = 2130903041;

    private Layout()
    {
    }
}

我使用VS 2010 MFA 4.0和我的项目都瞄准Android 4.0的。我曾尝试清洁和放大器;建立,删除 /斌 /的OBJ 文件夹,没有运气。
任何帮助将是非常美联社preciated。

I am using VS 2010 with MFA 4.0 and my projects are targeting Android 4.0. I have tried Clean & Build, Removing /Bin and /Obj folder, with no luck. Any help would be much appreciated.

推荐答案

这似乎是 MonoDroid的,这里是的链接错误在Xamarin的Bugzilla

This appeared to be a bug in MonoDroid, here is the link to the bug in Xamarin bugzilla

这是由 Resource.Designer.cs 在MFA库项目引起了一个不同的ID(INT)值比主项目在其 Resource.Designer.cs 文件。

This is caused by the Resource.Designer.cs in the MFA library project has a different ID (int) values than what the main project has in its Resource.Designer.cs file.

我已经摸索出了解决方法吧。在我的 mainApp 我手动调用 mainApp.Resources.UpdateIdValues​​(); 这将更新资源中的其他MFA库项目的ID值

I have worked out a workaround for it. In my mainApp I manually call mainApp.Resources.UpdateIdValues(); and that would update the Resources id values in the other MFA library projects

Xamarin表示,这个bug在4.6.4解决。我没有测试此修复程序,虽然

Xamarin said that this bug was resolved in 4.6.4. I have not tested this fix though

这篇关于Resource.Layout.filename将返回错误的布局文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆