View Pager inside detail fragment of master detail flow 被调用但未显示

View Pager inside detail fragment of master detail flow is called but not shown

我已经在主细节流程的细节中设置了一个视图寻呼机 activity 它似乎在工作(打印日志)但是视图没有出现所以这里是食谱细节布局拿着视图寻呼机这是细节片段

<?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true"
tools:context=".recipeDetailActivity"
tools:ignore="MergeRootFrame">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="recipe detail"
    android:textSize="22sp"/>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

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

当我 运行 应用程序时,上面的文本视图确实显示在布局中,视图寻呼机应该为列表中的每个项目加载布局(列表中肯定有项目)这个布局也有一个大文本视图(仅用于测试目的)但此布局未显示,这是我的视图寻呼机的整个适配器,因为它内部没有任何复杂的东西

public class CustomPagerAdapter extends PagerAdapter {

private Context mContext;
private ArrayList<Step> steps;
private String TAG = "CstmPgAdptr";

public CustomPagerAdapter(Context context, ArrayList<Step> adapterSteps) {
    mContext = context;
    this.steps = adapterSteps;
}

@Override
public Object instantiateItem(ViewGroup collection, int position) {
    LayoutInflater inflater = LayoutInflater.from(mContext);
    Step step = steps.get(position);
    ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.recipe_detail, collection,false);
    TextView descriptionText = layout.findViewById(R.id.recipe_detail);
    descriptionText.setText(step.getDescription());
    Log.d(TAG,"new view called");
    return layout;
}

@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
    collection.removeView((View) view);
}

@Override
public int getCount() {
    //return CustomPagerEnum.values().length;
    return steps.size();
}

@Override
public boolean isViewFromObject(View view, Object object) {
    return view == object;
}

@Override
public CharSequence getPageTitle(int position) {
    return steps.get(position).getShortDescription();
}

} 

当我在包含视图寻呼机的片段上滑动时,此日志 Log.d(TAG,"new view called");每次都会打印,这意味着它正在工作但未显示,而且任何布局中都没有滚动视图(看到这可能是一个问题)

编辑

添加了食谱详细布局

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".recipeDetailActivity"
tools:ignore="MergeRootFrame">


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

    <android.support.v7.widget.Toolbar
        android:id="@+id/detail_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

<com.google.android.exoplayer2.ui.SimpleExoPlayerView
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:layout_margin="@dimen/default_padding"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/app_bar" />

<TextView
    android:id="@+id/recipe_detail_text"
    android:gravity="center"
    style="?android:attr/textAppearanceLarge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/default_padding"
    android:textIsSelectable="true"
    app:layout_constraintTop_toBottomOf="@id/video_view"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent" />

<TextView
    android:id="@+id/recipe_detail2"
    android:gravity="center"
    style="?android:attr/textAppearanceLarge"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/default_padding"
    android:text="@string/app_name"
    android:textIsSelectable="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent" />



</android.support.constraint.ConstraintLayout>

好的,那是我的错。我添加了这个

collection.addView(layout);

它工作正常