CoordinatorLayout导致下一个片段底部被剪切/移出屏幕

时间:2019-07-15 07:24:02

标签: android fragment android-coordinatorlayout

如果Fragment1具有CoordinatorLayout和CollapsingToolbarLayout,则从Fragment1到Fragment2的片段事务将导致Fragment2中的底部对齐按钮被切出/显示在屏幕之外。

如果我用LinearLayout替换CoordinatorLayout,则Fragment2中的问题就会消失

尝试删除片段交易自定义动画。仍然不工作

fragment1.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/htab_maincontent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:layoutDirection="rtl"
    android:textDirection="ltr">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/htab_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/htab_collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="259dp"
            android:background="#fff"
            app:contentScrim="#fff"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager
                android:id="@+id/autoScrollViewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax" />


            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <!--toolbar content-->


            </androidx.appcompat.widget.Toolbar>


        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingBottom="10dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


            <!-- content-->

        </LinearLayout>
    </androidx.core.widget.NestedScrollView>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

fragment2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutDirection="rtl"
    android:orientation="vertical"
    android:textDirection="rtl"
    tools:context=".RFQFragment">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
           <!--toolbar content-->
    </androidx.appcompat.widget.Toolbar>


    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="16dp"
            android:paddingRight="16dp">


<!-- content-->


        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

    <Button

        android:id="@+id/send"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="8dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="16dp"
        android:background="@drawable/button_bg_enabled"
        android:gravity="center"
        android:text="@string/send"
        android:textAllCaps="false"
        android:textColor="@color/enable_able_text_color_selector"
        android:textSize="18dp"

        />


</LinearLayout>

1 个答案:

答案 0 :(得分:0)

删除android:fitsSystemWindows =“ true”解决了该问题