将片段添加到 CoordinatorLayout
Add fragment to CoordinatorLayout
您似乎无法将片段添加到 CoordinatorLayout。当我尝试插入一个时,没有任何崩溃,但片段只是没有出现,但是当我评估它的尺寸时,它们是非零的。如果我将 CoordinatorLayout
更改为 RelativeLayout
片段就会出现。如果我将 EditText
添加到 CoordinatorLayout
,EditText
就会出现。为什么片段没有出现在 CoordinatorLayout
中?
我的XML如下:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="com.mypackage.Behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
我正在用我的片段替换 FrameLayout
如下:
getChildFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, myFragment, MyFragment.TAG)
.commit();
在我的例子中,问题实际上出在我添加的片段视图上。它的边距使它脱离了屏幕。问题中的方法有效。
您似乎无法将片段添加到 CoordinatorLayout。当我尝试插入一个时,没有任何崩溃,但片段只是没有出现,但是当我评估它的尺寸时,它们是非零的。如果我将 CoordinatorLayout
更改为 RelativeLayout
片段就会出现。如果我将 EditText
添加到 CoordinatorLayout
,EditText
就会出现。为什么片段没有出现在 CoordinatorLayout
中?
我的XML如下:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="com.mypackage.Behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
我正在用我的片段替换 FrameLayout
如下:
getChildFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, myFragment, MyFragment.TAG)
.commit();
在我的例子中,问题实际上出在我添加的片段视图上。它的边距使它脱离了屏幕。问题中的方法有效。