Android - 当应用程序在后台时,回收站 View 会调整大小

标签 android xml android-layout android-fragments android-recyclerview

我的应用程序中有一个非常奇怪的错误。每次我打开我的应用程序时,我的 View 都运行良好,但是当我尝试将我的应用程序置于后台并再次打开我的应用程序时,我的回收器 View 会调整大小。

这里有一张图片来恰本地描述它:

这是正确的图片:

enter image description here

当应用程序在后台运行时,这张图片弄乱了我的 recyclerview,然后我再次打开它。

enter image description here

有时我的 recyclerview 中的所有图像都消失了。这是屏幕截图:

enter image description here

这是我的 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();

   }
 }

这是我的 View 寻呼机布局:

<?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>

这是我的列表布局:

<?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>

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

PS:该错误仅出现在选定的手机上。不是全部。我们已经在 Samsung Galaxy s8+ 上对此进行了测试,它运行良好。

最佳答案

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

即使这解决了问题,我仍然不知道为什么会首先出现错误。

关于Android - 当应用程序在后台时,回收站 View 会调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49813505/

相关文章:

java - 没有为 Content-Type : application/json 定义解析器

android.content.res.Resources$NotFoundException : File res/mipmap-xhdpi-v4/ic_copyright_black_24dp. png 来自 xml 类型 xml 资源 ID #0x7f0d0007

java - 如何通过JAXB xml解析获取特定元素?

c# - 在不知道名称的情况下从节点解析多个元素

android - 如何阻止Android应用程序在其上绘制? (避免Cloack&Dagger攻击)

android - Android 中的书架

java - Android Studio 2.3 更新后加载项目时出错

android - TextView#setMovementMethod(LinkMovementMethod.getInstance()) 正在破坏链接显示

android - 如何使按钮重定向到另一个 xml 页面

android - 在菜单中添加切换按钮以停止和启动服务