【问题标题】:Android ImageView can not locate resource where bitmap canAndroid ImageView 找不到位图可以找到的资源
【发布时间】:2020-05-12 16:48:14
【问题描述】:

xamarin.forms 有 a tutorial 用于在 android 中创建启动画面

这段代码是我遵循教程的结果它可以工作

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <color android:color="@color/splash_background"/>
  </item>
  <item>
    <bitmap
      android:src="@drawable/monstersplash"
      android:tileMode="disabled"
      android:gravity="fill_vertical|fill_horizontal"/>
  </item>
</layer-list>

但现在我还希望我的图像在页面上适合宽高比。

我发现一些帖子建议使用以下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/splashlinearlayout"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
      <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/monstersplash"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter" ></ImageView>
    </LinearLayout>

但此代码会导致 ResourcesNotFoundException:android.content.res.Resources$NotFoundException: Drawable com.companyname.BB.App:drawable/splash_screen with resource ID #0x7f070141

我尝试了层列表/线性布局的不同配置,但不知何故 Imageview 似乎无法加载我的 monstersplash.png 图像,而源参数与位图相同。 有什么想法吗?

完整上下文: 上述代码位于 drawable/splash_screen.xml 在我的 styles.xml 中,我有一个对 drawable 的引用,如下所示:

<style name="SplashTheme" parent ="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
    <item name="android:windowNoTitle">true</item>  
    <item name="android:windowFullscreen">true</item>  
    <item name="android:windowContentOverlay">@null</item>  
    <item name="android:windowActionBar">true</item>  
  </style>

我创建了一个引用主题的 splashactivity

[Activity(Theme = "@style/SplashTheme", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : AppCompatActivity
    {

【问题讨论】:

    标签: android xamarin.forms imageview android-bitmap


    【解决方案1】:

    因为它在位图中工作。该问题可能是由 IDE 或项目缓存引起的。

    1. 删除项目中的binobj文件夹,然后清理并 重建它。
    2. 删除文件 Resource.design.cs 中的所有内容,然后重建项目。

    如果还是不行,你可以新建一个项目,看看问题是否依然存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-24
      • 2015-07-12
      • 1970-01-01
      • 2018-12-07
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多