【问题标题】:How to put Multiple Views inside Material design Collapsing-Toolbar Layout如何在材料设计中放置多个视图折叠工具栏布局
【发布时间】:2015-10-16 10:33:35
【问题描述】:

我在 Activity 中使用折叠工具栏。我想在其中显示一个列表,为此我使用 RecyclerView。这工作正常。但现在我想在 Recyclerview 下方显示一个按钮。正如我red some where 我们只能在 collpasing-toolbar 布局中放置一个可滚动元素。我已经有一个 Recyclerview 我怎么能在它下面放一个按钮?我知道如果我使用 nestedScrollview 可以放置多个视图,但它不适用于 Recyclerview。

我尝试了什么

我尝试使用nested-scrollview 来显示recyclerview 和按钮,但是recyclerview 在嵌套scrollview 中不起作用。以下是我的布局xml 代码。

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

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">

            <com.andy.app.util.ui.SquareImageView
                android:id="@+id/Icon"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7" />

            <View
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/groupIcon"
                android:background="@drawable/coll_toolbar_image_gradient" />

        </RelativeLayout>


        <android.support.v7.widget.Toolbar
            android:id="@+id/anim_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.v7.widget.RecyclerView
    android:id="@+id/List"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/transparent_white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

   <Button
    android:layout_width="fill_parent"
    android:layout_height="60dp" />

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

【问题讨论】:

    标签: android android-layout android-5.0-lollipop material-design android-collapsingtoolbarlayout


    【解决方案1】:

    如果您希望按钮随视图滚动,您可以在 RecyclerView 的最后一行添加一个按钮。只需使用正确的 ViewHolder 插入按钮布局并覆盖 RecyclerView 的 getItemViewType(int position) 方法即可膨胀正确的视图并绑定它。

    如果您想要一个静态按钮,只需使用任何合适的布局(如 LinearLayout)包装您的 RecyclerView 并像往常一样添加按钮。

    【讨论】:

      猜你喜欢
      • 2016-09-20
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多