膨胀ViewStub以覆盖整个内容视图

时间:2017-06-22 22:04:39

标签: android android-layout viewstub

我想通知ViewStub来覆盖整个内容视图。

ViewStub包含在活动的CoordinatorLayout根视图中。此外,活动的布局包含Toolbar设置为ActionBar来自.setSupportActionBar()

以下是活动的布局:

<android.support.design.widget.CoordinatorLayout 
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <ViewStub
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/stub"
        android:inflatedId="@+id/subView"
        android:layout="@layout/loading_view"
        />

</android.support.design.widget.CoordinatorLayout>

目前,ViewStub会膨胀,只占用Toolbar下的空间。我怀疑这可能是因为Toolbar被设置为ActionBar,如前所述。如何让这个ViewStub充气,以便它占用整个内容视图?

1 个答案:

答案 0 :(得分:0)

我可以通过ActionBar手动隐藏getSupportActionBar.hide()来获得所需的结果。这使得膨胀的布局占据了整个内容视图。

如果有人知道更好的解决方案,请提交。