【问题标题】:Place View pager below AppBarLayout在 AppBarLayout 下方放置 View 寻呼机
【发布时间】:2018-02-23 17:20:15
【问题描述】:

我在 CollapsableToolbar 内的 NestedScrollView 中有 View Pager。但是 ViewPager 片段的内容隐藏在 AppBarLayout 后面。 Viewpager 是完全可滚动的。

如何解决这个问题?

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="128dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="128dp"
            android:background="@color/colorPrimary">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="128dp"
                android:orientation="vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="64dp"
                    android:gravity="center"
                    android:textSize="32dp"
                    android:fontFamily="@font/amaranth"
                    android:text="@string/app_name" />
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="59dp"
                    android:background="@drawable/rounded_corners"
                    android:layout_marginRight="14dp"
                    android:hint="Search"
                    android:padding="10dp" />
            </LinearLayout>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom"
    android:fillViewport="true">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.CardView
    app:layout_anchor="@id/nested_scroll_view"
    app:layout_anchorGravity="bottom"
    android:id="@+id/card"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    app:cardElevation="1dp"
    app:cardMaxElevation="3dp">

    <android.support.design.widget.TabLayout

        android:id="@+id/tablayout"
        style="@style/MyCustomTabTextAppearance"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/whiteColor"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/tabBackgroundColor"
        app:tabMode="fixed">

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

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

这里是截图。 我想一定是appbarlayout的滚动行为。 我是 coordinatorlayout 的新手。

【问题讨论】:

    标签: android material-design android-coordinatorlayout android-collapsingtoolbarlayout


    【解决方案1】:

    添加

    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    

    到你的nestedscrollView

    【讨论】:

    • 太棒了!它有效..但是app:layout_behavior 实际上做了什么?
    • 它允许您在 appBarLayout 下滚动并使用该行为在您的 appBar 下保持视图
    • 好的!注意到这个答案
    • 如果您得到答案,请随时更新.. :) @Shantanu
    猜你喜欢
    • 2011-01-02
    • 2016-11-15
    • 1970-01-01
    • 2022-11-18
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    相关资源
    最近更新 更多