2

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.

Picture

My current code:-

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

2
  • try removing the scroll flags. that way your AppBar will be fixed and thus your recycler view wont move either Commented Jun 26, 2016 at 19:38
  • I dont want my recycler view to stop scrolling. I jist want that my card view scrolls if I scroll down at position of cardview Commented Jun 26, 2016 at 19:50

1 Answer 1

3

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

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I have no compulsion on using card view. I just want my HastTagView (which is a textview) to be able to scroll instead of increasing the height of textview.
Then just wrap the hastagview inside of a Scrollview. Although your hashtagview will have its full size, the visible part will be determined by the scrollview's size. Hence, you can decide the visible portion of your view just by changing the scrollview's height. I hope this helps :)
So I just remove the cardview element and the rest of code is fine
And replace the Linearlayout inside it with a Scrollview, it should work ;)
Sure. If it works, don't forget to accept + vote! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.