我有一个具有以下层次结构的布局
列表.xml
<android.support.constraint.ConstraintLayout
android:id="@+id/layout_content"
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.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@+id/layout_content"
app:layout_constraintStart_toStartOf="@+id/layout_content"
app:layout_constraintTop_toTopOf="@+id/layout_content"
tools:layout_constraintEnd_creator="0"
tools:layout_constraintStart_creator="0"
tools:layout_editor_absoluteX="0dp">
<com.fastaccess.cheaphlight.ui.widgets.recyclerview.DynamicRecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/spacing_large"
app:layoutManager="@string/staggered_layout_manager"
app:layout_constraintLeft_toLeftOf="@+id/refresh"
app:spanCount="2"
tools:listitem="@layout/county_row_item"/>
</android.support.v4.widget.SwipeRefreshLayout>
<include
layout="@layout/empty_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@+id/layout_content"
app:layout_constraintStart_toStartOf="@+id/layout_content"
app:layout_constraintTop_toTopOf="@+id/layout_content"
tools:layout_constraintBottom_creator="0"
tools:layout_constraintEnd_creator="0"
tools:layout_constraintStart_creator="0"
tools:layout_constraintTop_creator="0"/>
<include
layout="@layout/progress_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingBottom="?attr/actionBarSize"
app:layout_constraintBottom_toBottomOf="@+id/layout_content"
app:layout_constraintEnd_toEndOf="@+id/layout_content"
app:layout_constraintStart_toStartOf="@+id/layout_content"
app:layout_constraintTop_toTopOf="@+id/layout_content"
tools:layout_constraintBottom_creator="0"
tools:layout_constraintEnd_creator="0"
tools:layout_constraintStart_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="205dp"
tools:layout_editor_absoluteY="382dp"/>
</android.support.constraint.ConstraintLayout>
empty_layout.xml
<android.support.constraint.ConstraintLayout
android:id="@+id/empty_layout"
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="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/image_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_sad_face"
app:layout_constraintBottom_toBottomOf="@+id/empty_layout"
app:layout_constraintEnd_toEndOf="@+id/empty_layout"
app:layout_constraintStart_toStartOf="@+id/empty_layout"
app:layout_constraintTop_toTopOf="@+id/empty_layout"
app:layout_constraintVertical_bias="0.19"
tools:ignore="ContentDescription"
tools:layout_constraintBottom_creator="0"
tools:layout_constraintEnd_creator="0"
tools:layout_constraintStart_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="145dp"
tools:layout_editor_absoluteY="321dp"/>
<com.fastaccess.cheaphlight.ui.widgets.FontTextView
android:id="@+id/text_message"
style="@style/TextAppearance.AppCompat.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image_message"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/spacing_normal"
android:gravity="center_horizontal"
android:padding="@dimen/spacing_s_large"
android:textColor="@color/divider"
app:layout_constraintEnd_toEndOf="@+id/empty_layout"
app:layout_constraintStart_toStartOf="@+id/empty_layout"
app:layout_constraintTop_toBottomOf="@+id/image_message"
tools:layout_constraintEnd_creator="0"
tools:layout_constraintStart_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="205dp"
tools:layout_editor_absoluteY="441dp"
tools:text="Error Message"/>
<com.fastaccess.cheaphlight.ui.widgets.FontButton
android:id="@+id/reload_button"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_message"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/spacing_normal"
android:padding="@dimen/spacing_s_large"
android:text="@string/reload"
android:textColor="@color/accent"
app:layout_constraintEnd_toEndOf="@+id/empty_layout"
app:layout_constraintStart_toStartOf="@+id/empty_layout"
app:layout_constraintTop_toBottomOf="@+id/text_message"
tools:layout_constraintEnd_creator="0"
tools:layout_constraintStart_creator="0"
tools:layout_constraintTop_creator="0"
tools:layout_editor_absoluteX="205dp"
tools:layout_editor_absoluteY="441dp"/>
</android.support.constraint.ConstraintLayout>
progress_layout.xml
<ProgressBar
android:id="@+id/progress_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="?attr/actionBarSize"
android:visibility="gone"
tools:visibility="visible"/>
在我的 Fragment 类中,我隐藏 SwipeRefreshLayout 及其子 RecyclerView 并显示 empty_layout。这很好用,但是如果我关闭和打开设备屏幕,empty_layout 就会消失。
仅供参考:我已将嵌套 ConstrainLayout 的可见性设置为始终可见,但如果我关闭/打开屏幕,它就会消失。
仅供参考:如果我曾经显示 ProgressView,则 ProgressView 在屏幕上保持可见开/关我假设它是因为 ProgressView 没有包裹在嵌套的 ConstraintLayout 下!?。
关于为什么嵌套的 ConstrainLayout 仅在屏幕开/关时消失,而在我旋转屏幕时它仍然存在的任何想法?