0

ich habe ein Layout, das die folgende Hierarchienested ConstraintLayout Sichtbarkeit auf dem Bildschirm ON/OFF

<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

list.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 hat .xml

in meiner Fragment-Klasse, ich verstecke das SwipeRefreshLayout mit seinem Kind RecyclerView und zeigt das empty_layout. das funktioniert gut, aber wenn ich jemals den Gerätebildschirm AUS & ON schaltet, verschwindet das empty_layout.

FYI: Ich habe die Sichtbarkeit für das verschachtelte ConstrainLayout festgelegt, damit es immer sichtbar ist, aber wenn ich den Bildschirm aus-/wieder einschalte, verschwindet es.

FYI: Wenn ich jemals die ProgressView zeigte, bleibt die ProgressView auf dem Bildschirm sichtbar on/off ich nehme an, dass ProgressView nicht unter verschachtelte ConstraintLayout eingewickelt ist!?.

eine Idee, warum die verschachtelte ConstrainLayout nur auf dem Bildschirm verschwindet, während es bleibt, wenn ich den Bildschirm gedreht habe?

+0

Können Sie bitte [ein minimales, vollständiges und überprüfbares Beispiel erstellen] (http://stackoverflow.com/help/mcve)? Sie nehmen an, dass es mit 'ConstraintLayout' zu tun hat, also können Sie alle anderen Ansichten entfernen, behalten Sie ein' ConstraintLayout' in einem anderen 'ConstraintLayout' mit einigen farbigen Hintergründen für Sichtbarkeit und sehen Sie, ob das seltsame Verhalten immer noch da ist? –

Antwort

0

hmmm, seltsam, ich wickelte die empty_layout.xml unter FrameLayout und alles funktioniert gut. die Layout wurde wie unten:

<FrameLayout 
    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"> 

    <android.support.constraint.ConstraintLayout 
     android:id="@+id/holder" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center"> 

     <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/holder" 
      app:layout_constraintEnd_toEndOf="@+id/holder" 
      app:layout_constraintStart_toStartOf="@+id/holder" 
      app:layout_constraintTop_toTopOf="@+id/holder" 
      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/holder" 
      app:layout_constraintStart_toStartOf="@+id/holder" 
      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/holder" 
      app:layout_constraintStart_toStartOf="@+id/holder" 
      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> 
</FrameLayout> 

jedoch diese nicht beantwortet meine Frage, warum tut der Nested ConstraintLayout verschwindet, wenn der Bildschirm OFF & ON zurückgedreht, wenn mich jemand aufklären könnte, ich wäre dankbar.

Verwandte Themen