锁定设备后,ViewPager中的片段会被切断

时间:2018-04-06 12:49:58

标签: android android-fragments

每当我锁定然后解锁设备时,我的视图分页器中的片段会从底部切掉大部分片段,而在某些设备中,整个片段看起来已从视图中消失。我也注意到这个bug只出现在某些手机上。我已经在Vivo,Asus和LG手机上安装了带有棉花糖和牛轧糖版本的andorid的应用程序,一切正常但是当我使用Marshmallow在三星Galaxy J7 Prime上安装应用程序时,会发生错误。不过我已经在三星Galaxy S4上安装了应用程序,它仍然可以正常工作,没有任何问题。

ViewPager

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


<com.booking.rtlviewpager.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_toTopOf="parent">

</com.booking.rtlviewpager.RtlViewPager>

<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

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout >

RecyclerView项目布局

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/menu_item_color">

<ImageView
    android:id="@+id/image"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_centerInParent="true"
    android:contentDescription="@string/content_description"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintDimensionRatio="H,4:3"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

<View
    android:id="@+id/view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="@color/frosted_black"
    android:visibility="visible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="32dp"
    android:layout_marginStart="32dp"
    android:layout_marginTop="8dp"
    android:fontFamily="@font/frutigerltarabic_75black"
    android:gravity="start"
    android:includeFontPadding="false"
    android:shadowColor="@android:color/black"
    android:shadowDx="1"
    android:shadowDy="1"
    android:shadowRadius="1"
    android:textAllCaps="true"
    android:textColor="@android:color/white"
    android:textSize="20sp"
    app:layout_constrainedHeight="true"
    app:layout_constrainedWidth="true"
    app:layout_constraintBottom_toBottomOf="@+id/image"
    app:layout_constraintEnd_toEndOf="@+id/image"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="@+id/image"
    app:layout_constraintTop_toBottomOf="@+id/price_container"
    app:layout_constraintVertical_bias="0.0"/>


<android.support.constraint.ConstraintLayout
    android:id="@+id/price_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="32dp"
    android:layout_marginStart="32dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/menu_price_bg"
    app:layout_constraintBottom_toBottomOf="@+id/image"
    app:layout_constraintEnd_toEndOf="@+id/image"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/image"
    app:layout_constraintVertical_bias="0.3">

    <TextView
        android:id="@+id/price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:fontFamily="@font/frutigerltarabic_55roman"
        android:includeFontPadding="false"
        android:textColor="@android:color/white"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"/>

    <TextView
        android:id="@+id/sar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="4dp"
        android:fontFamily="@font/frutigerltarabic_55roman"
        android:includeFontPadding="false"
        android:textColor="@android:color/white"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="@+id/price"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@+id/price"
        app:layout_constraintTop_toTopOf="@+id/price"
        app:layout_constraintVertical_bias="0.0"
        android:layout_marginRight="8dp"
        android:layout_marginLeft="4dp"/>

</android.support.constraint.ConstraintLayout>

0 个答案:

没有答案