操作栏由协调器布局推动,如下图所示:
(ActionBar看起来缺少它的上部,如果我返回到另一个活动,它将保留缺少上部的部分)
android - 由CoordinatorLayout推送的Actionbar-LMLPHP
我错过了什么?
我可以在viewpager中使用coordinatorlayout还是不应该在viewpager中使用它?
可以在片段中使用坐标布局。
Test.xml:

  <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/CollapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:collapsedTitleGravity="center"
            app:collapsedTitleTextAppearance="@style/TextAppearance.Design.CollapsingToolbar.Expanded.Shadow"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="50dp"
            app:expandedTitleMarginStart="50dp"
            app:expandedTitleTextAppearance="@style/TextAppearance.Design.CollapsingToolbar.Expanded.Shadow"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/IV"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerInside"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>


    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/whiteBackground"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                app:cardBackgroundColor="@color/grayBackground"
                app:cardCornerRadius="5dp"
                app:cardElevation="5dp">

                <TextView
                    android:id="@+id/tv1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:padding="@dimen/activity_horizontal_margin"
                    android:textColor="@color/colorPrimary"
                    android:textStyle="bold" />
            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                app:cardBackgroundColor="@color/grayBackground"
                app:cardCornerRadius="5dp"
                app:cardElevation="5dp">

                <TextView
                    android:id="@+id/tv2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:lineSpacingExtra="8dp"
                    android:padding="@dimen/activity_horizontal_margin"
                    android:textSize="20sp" />
            </android.support.v7.widget.CardView>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/FAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        app:backgroundTint="@color/colorPrimaryDark"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|left|start"
        app:rippleColor="@android:color/darker_gray"
        app:srcCompat="@drawable/ic_more_black_24dp" />

</android.support.design.widget.CoordinatorLayout>

最佳答案

我通过从android:fitsSystemWindows="true"中删除CoordinatorLayout解决了这个问题。

关于android - 由CoordinatorLayout推送的Actionbar,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45400747/

10-10 06:25