1

CoordinatorLayout不顯示ViewStub子代。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(); 
     } 
    } 
+0

你有沒有找到一個解決方案嘗試一下呢?我有同樣的問題 –

+0

@JeffThomas不幸的是,我沒有找到解決方案。 – kazhiu

回答

0

使用ViewStubCompat代替ViewStub

+0

Dosen't work :( – kazhiu