android - 我的 ImageView 没有出现在我的设备屏幕上

标签 android xamarin

我为该布局创建了一个布局和一个 Activity 。

在布局中,我只有一个带有 png 图像的 ImageView,它位于 Resources/Drawables 中。

当我在我的设备中启动应用程序时,ImageView 没有出现在屏幕上。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:gravity="center"
android:visibility="visible"
tools:visibility="visible">
<ImageView
    android:layout_width="350.0dp"
    android:layout_height="279.5dp"
    android:id="@+id/OpeningLogo"
    android:layout_gravity="center"
    android:visibility="visible"
    tools:visibility="visible"
    android:src="@drawable/logo"
    android:adjustViewBounds="true" />
</LinearLayout>

这是 Activity 代码:

namespace *********
{
    [Activity(Label = "xxxxxxxxx", MainLauncher = true, Icon = "@drawable/Logo")]
    public class OpeningActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Opening);

            Intent GoToLogin = new Intent(this, typeof(MainActivity));
            Thread.Sleep(5000);
            this.Finish();
            StartActivity(GoToLogin);
        }
    }
}

如果你想让我添加更多内容,请告诉我。

提前致谢!

最佳答案

问题是您阻塞了该 Activity 的 UI 线程,并且它从未真正按预期显示。 UI 线程没有时间在屏幕上实际绘制任何内容。

相反,你应该这样做:

namespace GridSocios
{
    [Activity(Label = "xxxxxxxxx", MainLauncher = true, Icon = "@drawable/Logo", NoHistory = true)]
    public class OpeningActivity : Activity
    {
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Opening);

            await Task.Delay(5000);

            var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);
        }
    }
}

另请注意设置了 NoHistory = true 标志。这意味着您在离开此 Activity 后将无法导航回该 Activity。

关于android - 我的 ImageView 没有出现在我的设备屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36649678/

相关文章:

java - 如何阅读特定邮件ID的邮件

android - 将自定义值保存到android中的首选项?

c# - "Invalid Swift Support"在 Xamarin.iOS 中使用 native Swift 库

xamarin - 有没有办法通过Xamarin Forms应用程序显示 native iOS和Android忙碌指示器?

ios - ios 更新到 ios 11.0 后,我的地理定位器不起作用,xamarin.forms

Android 应用程序单元测试

java - 如何在android中从用户那里获取整数,操作并放置在另一个文本框中

android - 使用 webview 读取文件?

c# - “资源”在当前上下文中不存在

c# - Uri 类的反射 GetValue 失败