android - CoordinatorLayout 推送的 Actionbar

标签 android android-layout android-coordinatorlayout

操作栏被 CoordinatorLayout 推送,如下图所示:

(ActionBar 看起来缺少它的上半部分,如果我返回到另一个 Activity ,它仍然缺少上半部分)

enter image description here

  • 我错过了什么?
  • 我可以在 ViewPager 中使用 CoordinatorLayout 还是不应该在其中使用它?
  • CoordinatorLayout可以在fragment中使用吗

    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>
    

最佳答案

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

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

相关文章:

android - 隐藏工具栏时无法启用 webview 的滚动行为

imageView 上的 android setAlpha 进入 CollapsingToolbarLayout 不起作用

android - Gson 错误 JellyBean

android - 在 onCreateView() 方法之外访问 View

android - boundCenter()/boundCenterBottom() 必须用于 ItemizedOverlay 中的标记?

android - 如何使android全屏 Activity 中的操作栏始终可见

java - 如何从右到左放置textView的垂直滚动条?

android - 以编程方式滚动 Recycler View 不会更新 CoordinatorLayout.Behaviour,而通过触摸滚动更新 CoordinatorLayout.Behaviour

android - 添加新联系人(36 项)

android - Google Play 游戏、Firebase 和新的 Google 登录