【问题标题】:CoordinatorLayout doesn't show ViewStub childCoordinatorLayout 不显示 ViewStub 子项
【发布时间】:2015-10-06 11:35:11
【问题描述】:

CoordinatorLayout 不显示 ViewStub 子级。

我尝试膨胀 ViewStub,但视图没有显示。我是否必须向我的 ViewStub 添加一些布局行为或一些标志?

有什么想法吗?

下面是我的布局:

activity_main.xml

    <android.support.design.widget.CoordinatorLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/application_bar"
        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"
            android:background="?attr/colorPrimary"
            app:title="Test"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/MyCustomTabLayout" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/moments_bg"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <ViewStub
        android:id="@+id/tutorial"
        android:inflatedId="@+id/tutorial_import"
        android:layout="@layout/tutorial"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

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

tutorial.xml

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#99000000">

    <RelativeLayout
        android:layout_width="280dp"
        android:layout_height="300dp"
        android:layout_gravity="bottom"
        android:layout_marginBottom="50dp"
        android:background="@drawable/add_moment_oval">

        <TextView
            android:id="@+id/tutorial_desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textColor="@color/default_text_color"
            android:textSize="14dp"
            android:text="test"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tutorial_desc"
            android:textColor="@color/accent"
            android:textSize="14dp"
            android:text="accept"
            android:theme="@style/DashboardButton"
            style="?android:attr/borderlessButtonStyle" />

    </RelativeLayout>
</FrameLayout>

MainActivity.java

 @OnClick(R.id.add_button)
    public void onAddButtonClicked(){

        View v = findViewById(R.id.tutorial);

        if (v instanceof ViewStub) {
            ((ViewStub)v).inflate();
        }
    }

【问题讨论】:

  • 您找到解决方案了吗?我也有同样的问题
  • @JeffThomas 不幸的是,我没有找到解决方案。

标签: android android-layout android-coordinatorlayout viewstub


【解决方案1】:

尝试使用ViewStubCompat 而不是ViewStub

【讨论】:

    猜你喜欢
    • 2015-03-11
    • 2017-09-03
    • 1970-01-01
    • 2019-01-18
    • 2018-02-26
    • 2023-03-08
    • 1970-01-01
    • 2011-04-02
    • 2016-04-24
    相关资源
    最近更新 更多