cardView + RecyclerView布局中的Android滚动功能 [英] Android scrolling function in cardView + RecyclerView layout

查看:126
本文介绍了cardView + RecyclerView布局中的Android滚动功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我首先具有cardview,然后具有RecyclerView. 使用我现有的代码,我可以滚动整个页面.但是我希望我也只能滚动卡片视图项.目前,当我尝试滚动cardview时,会滚动整个布局.

In my application I have first the cardview and then RecyclerView. Using my existing code I am able to scroll the whole page. But I want that I can also scroll only the card view items. Currently when I try to scroll cardview the complete layout is scrolled.

我当前的代码:-

<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"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp"
        android:fitsSystemWindows="true">

        <android.support.v7.widget.CardView style="@style/Card">

            <LinearLayout style="@style/CardContainer"
                android:isScrollContainer="true">


                    <com.greenfrvr.hashtagview.HashtagView
                        android:id="@+id/hashtags6"
                        style="@style/HashtagView"
                        app:rowGravity="center"
                        app:rowMode="stretch"
                        app:selectionMode="true"
                        app:tagBackground="@drawable/item_bg_1"
                        app:tagForeground="@drawable/flat_button_light"
                        app:tagPaddingBottom="@dimen/padding_vertical"
                        app:tagPaddingLeft="@dimen/padding_horizontal"
                        app:tagPaddingRight="@dimen/padding_horizontal"
                        app:tagPaddingTop="@dimen/padding_vertical"
                        app:tagTextColor="#E5E5E5" />



            </LinearLayout>
        </android.support.v7.widget.CardView>




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

    </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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

推荐答案

尽管谷歌强烈建议避免使卡片可滚动(请参阅本文

Although google emphatically recommends avoiding making a card scrollable (see this article https://material.google.com/components/cards.html#cards-behavior)

您真正要做的就是用ScrollView包装卡中的内容.

All you really have to do is wrap the contents of your card with a ScrollView.

https://developer.android.com/reference/android/widget/ScrollView.html

如果您的设计允许,我建议您在卡的底部放置一个动作按钮,以使其展开并在单击时收缩.

If your design allows it, I recommend that you place a an action button at the bottom of the card that expands it and contracts it when it is clicked.

这篇关于cardView + RecyclerView布局中的Android滚动功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆