一切正常我可以抽出抽屉和工具栏没问题,但我添加片段的"@+id/frame"
不可见。
XML
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.port.android.ui.ActivityMain">
<android.support.constraint.ConstraintLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.Guideline
android:id="@+id/guideline1"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.11463845"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="65dp" />
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="@+id/frame"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp"
app:layout_constraintTop_toTopOf="@+id/guideline1"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp">
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_view_header"
app:menu="@menu/menu_navigation">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="20dp">
<Button
android:id="@+id/btn_exit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="exitAddress"
android:text="Exit Address" />
</LinearLayout>
</android.support.design.widget.NavigationView>
在Android Studio布局检查器中,我清楚地看到SwipeRefreshLayout
中添加了"@+id/frame"
的片段,但您看不到任何显示内容。
这是碎片:
<?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:id="@+id/layout_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_refresh_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_chat_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
<ImageView
android:id="@+id/upload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_create_new_folder_black_24dp"
tools:layout_editor_absoluteY="41dp"
tools:layout_editor_absoluteX="16dp" />
<EditText
android:id="@+id/message_body"
android:layout_width="1dp"
android:layout_height="1dp"
android:hint="@string/message_hint"
tools:layout_editor_absoluteY="41dp"
tools:layout_editor_absoluteX="16dp" />
<Button
android:id="@+id/post_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/message_post"
tools:layout_editor_absoluteY="41dp"
tools:layout_editor_absoluteX="16dp" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>
这是我添加片段的方式:
mFragManager.beginTransaction()
.add(R.id.frame, (Fragment) Class.forName(tag).newInstance(), tag)
.addToBackStack(tag)
.commit();
我在这里做错了什么?