Android - 当应用在后台时,Recycler视图会调整大小

Pin*_*wer 10 xml android android-layout android-fragments android-recyclerview

我的应用程序上有这个非常奇怪的错误.每次我打开我的应用我认为完美的作品,但是当我试图把我的应用程序在后台,然后再次打开我的应用程序,我的看法回收重新调整.

这是一张正确描述它的图片:

这是正确的图像:

在此输入图像描述

当应用程序在后台时,这是弄乱我的recyclerview的图像,然后我再次打开它.

在此输入图像描述

有时我的recyclerview中的所有图像都消失了.这是一个截图:

在此输入图像描述

这是我的onResume()代码:

public void onResume()
 {
   Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
   if (fragment instanceof MenuFragment)
   {
     FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
     transaction.remove(fragment);
     transaction.commit();
     transaction = getSupportFragmentManager().beginTransaction();
     transaction.replace(R.id.fragment_container, fragment);
     transaction.addToBackStack(null);
     transaction.commit();

   }
 }
Run Code Online (Sandbox Code Playgroud)

这是我的查看分页器布局:

<?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:background="@drawable/app_background">
    <android.support.constraint.ConstraintLayout
        android:id="@+id/action_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <include
            android:id="@+id/nav_bar"
            layout="@layout/home_screen_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>

    <com.yotadevices.widget.RtlViewPager
        android:id="@+id/menuFragment_viewPager"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/transparent"
        app:layout_constraintBottom_toTopOf="@+id/buttons"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/nav_bar"/>
    <include
        android:id="@+id/buttons"
        layout="@layout/navigation_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/menuFragment_viewPager" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的列表布局:

<?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/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:orientation="vertical">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

您认为这里的问题是什么?

PS:该错误仅发生在选定的手机上.不是全部.我们在三星Galaxy s8 +上进行了测试,效果很好.

Pin*_*wer 2

我通过破坏部分包含的布局解决了这个问题。因此,我没有添加包含的布局,而是将所有包含的内容转移到主 XML 布局中。

尽管这解决了问题,但我仍然不知道为什么会出现该错误。