【发布时间】: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