【问题标题】:Text View does'nt scroll under Toolbar when anchored to app bar layout锚定到应用栏布局时,Textview 在工具栏下不滚动
【发布时间】:2016-09-03 10:20:04
【问题描述】:

所以,我想放置一个样式化的文本视图而不是 FAB,以便与将 fab 放置到锚点时具有相同的结果。问题是它不起作用,当滚动时,一半的文本视图仍然可见,即使是很难折叠的工具栏也被隐藏了。

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="match_parent"
    android:fitsSystemWindows="true">

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

        <!--android:fitsSystemWindows="true"-->

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

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

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

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

   <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


</android.support.v4.widget.NestedScrollView>


 <TextView
        android:id="@+id/details_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/layout_padding"
        android:background="@drawable/drawable_details_price_background"
        android:padding="@dimen/layout_padding"
        android:textColor="@color/textColorPrimary"
        app:layout_anchor="@id/app_bar_layout"
        app:layout_anchorGravity="bottom|left|end" />

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

如何使用文本视图而不是 FAB 来实现这样的行为?

【问题讨论】:

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


    【解决方案1】:
    <android.support.v4.widget.NestedScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
         <TextView
            android:id="@+id/details_price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/layout_padding"
            android:background="@drawable/drawable_details_price_background"
            android:padding="@dimen/layout_padding"
            android:textColor="@color/textColorPrimary"
            app:layout_anchor="@id/app_bar_layout"
            app:layout_anchorGravity="bottom|left|end" />
    
    </android.support.v4.widget.NestedScrollView>
    

    【讨论】:

    • 这个答案有一些解释会更有帮助
    猜你喜欢
    • 2015-12-09
    • 1970-01-01
    • 2020-12-11
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-03
    相关资源
    最近更新 更多