,c#,android,xamarin.android"/>

首页 > 解决方案 > Xamarin C# 安卓

问题描述

我正在开发一个 android 应用程序,我偶然发现了一个我无法通过的错误。我所有的研究都让我相信我缺少一些 xml 元素,但我不知道是什么,所以希望有更多专业知识的人能指出这一点。

我得到的视觉工作室错误是

Unhandled Exception:

Android.Views.InflateException: <Timeout exceeded getting exception details>

错误来自我的 roundbutton.xml 文件

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
  <solid android:color="#536878" />
  <corners android:bottomRightRadius="25dp"
      android:bottomLeftRadius="25dp"
      android:topRightRadius="25dp"
      android:topLeftRadius="25dp"/>
</shape>

我正在从我的主要活动 xml 中调用该代码,并且调用上述代码是:

<ImageButton
    android:src="@mipmap/baseline_settings_white_36"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/settingsButton_zone2"
    android:layout_marginBottom="0.0dp"
    android:background = "@mipmap/roundbutton"/>

那么,有没有人看到我在圆形按钮 xml 中遗漏了什么?如果我删除android:background="@mipmap/roundbutton"然后我不再收到错误并且我的应用程序运行。

提前致谢。

标签: c#androidxamarin.android

解决方案


所以事实证明我最终发现了这个问题。

我最终只是做一个解决方法,而不是使用 xml 文件来制作按钮圆形,我打算以编程方式在 C# 中使它们圆形。这行得通,但后来我最终弄清楚了为什么 xml 文件不起作用。

事实证明,我已将文件放在 mipmap/anydpi-v26 文件夹中。我的模拟器试图从它的 mipmap/xhdpi 文件夹中读取,因为它在那里不存在,所以我得到了超时。解决方案是将文件从 mipmap 文件夹中移出并移到不会因设备屏幕大小而改变的文件夹结构中。

希望这可以帮助其他人。


推荐阅读