向上滚动时Android折叠工具栏显示工具栏

时间:2015-10-27 09:46:19

标签: android material-design toolbar android-collapsingtoolbarlayout

在我的应用程序中,我有一个详细信息页面,其中包含折叠工具栏布局和下方的litview。当我向上滚动时,我需要只显示工具栏,当我移动到listview的顶部时显示完整的布局。

像这样:

enter image description here

这是我的代码,但它不起作用:

<?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="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <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">

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

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

    </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">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            app:cardElevation="@dimen/spacing_medium"
            app:cardUseCompatPadding="true">

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

                <TextView
                    android:id="@+id/title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/spacing_large"
                    android:layout_marginRight="@dimen/spacing_large"
                    android:layout_marginTop="@dimen/spacing_large"
                    android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

                <TextView
                    android:id="@+id/description"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/spacing_large"
                    android:text="@string/lorem_ipsum"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

            </LinearLayout>
        </android.support.v7.widget.CardView>
    </FrameLayout>
</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    style="@style/FabStyle"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|end" />

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

我使用app:layout_scrollFlags="scroll|enterAlways"作为工具栏,但它不起作用。有人可以帮我这个吗?

2 个答案:

答案 0 :(得分:1)

你的布局应该在这个结构中带有完美的标签....标签是视差效果的主要部分。 请点击此链接:https://github.com/antoniolg/MaterializeYourApp/tree/master/app/src/main/java/com/antonioleiva/materializeyourapp

;WITH CTE
AS (
    SELECT *
        ,ROW_NUMBER() OVER (
            PARTITION BY TPATransactionId
            ,Channel
            ,EIN ORDER BY TPATransactionId
            ) rn
    FROM @DebitCardTransaction
    )
UPDATE dt
SET [Status] = 'DUPPAST'
FROM @DebitCardTransaction DT
INNER JOIN cte c ON dt.TPATransactionId = c.TPATransactionId
    AND dt.Channel = c.Channel
    AND dt.EIN = c.EIN
WHERE rn > 1

SELECT *
FROM @DebitCardTransaction

答案 1 :(得分:0)

def virial_temp(M=row1[i][2],z=row1[i][3]):
     X = 0.7
     Y = 0.3
     mu = 1/(2*X + 0.75*Y)   #from GL's code
     v_v = math.sqrt(G*M*m_sun/(virial_rad(M,z)*1E+3*parsec))      #virial velocity [m/s]
     return (mu*m_p*v_v**2/(2*k_b))


line1 = plt.plot([namei - len(row1)*0.5, namej - len(row2)*0.5],[row1[i][3]*10, row2[j][3]*10], c=plt.cm.jet(j), lw=2, marker='o', markerfacecolor=plt.cm.rainbow(virial_temp(M=row1[i][2],z=row2[j][3])), markersize=1.5) 

这是一个有效的例子,thx AndroidStudio为他的回答