首页 > 解决方案 > 如何隐藏根视图,直到它准备好输入?

问题描述

我正在添加这样的布局OnCreate......

SetContentView(Resource.Layout.Main);

在它第一次出现和它准备好接收用户输入之间有一个难看的停顿。在此期间,它还覆盖了背景,它是一个加载场景。

因此,如何将布局及其控件设置为在完成构建之前不可见?

我试过这个...

var root = FindViewById<Layout>(Resource.Layout.Main);

root.Visibility = ViewStates.Invisible;

...但根是null.

标签: androidxamarin

解决方案


布局有它的 Main根视图,你可以控制这个视图来实现你的想法。在 XML 中:

  <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone">  //Initial status 

   .......

并使用 java 代码:

    ConstraintLayout root = (ConstraintLayout)findViewById(R.id.root);
    root.setVisibility(View.GONE);

推荐阅读