31462

Android: scrollview and recyclerview

Question:

I want to make an app that will list the books of every Writer.The screen has two cardview:

The first one with information about the writer and it will have always the same height.

The second one will have the list of his books. I want the second card to have limitless height i.e. the card will grow longer whenever you add a book.

At first I used a scrollview as root and inflated a row inside the card for every book saved in the database. Now i'm using a recyclerview inside the second card because it helped and simplified the code. But now I can scroll inside the card instead of all the screen and I don't want that to happen. How can i fix that?

The second card shouldn't be scrollable:

<a href="https://i.stack.imgur.com/879re.png" rel="nofollow"><img alt="Android application screenshot" class="b-lazy" data-src="https://i.stack.imgur.com/879re.png" data-original="https://i.stack.imgur.com/879re.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

This is the xml of the layout

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:fab="http://schemas.android.com/apk/res-auto" android:id="@+id/scrollView" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:fillViewport="true" android:nestedScrollingEnabled="true"> <RelativeLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:orientation="horizontal" card_view:cardCornerRadius="5dp" card_view:cardUseCompatPadding="true" android:id="@+id/scheda"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentStart="true"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Titolo" android:id="@+id/textView3" android:visibility="gone" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="" android:id="@+id/titolo" android:visibility="gone" android:inputType="textNoSuggestions"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Autore" android:id="@+id/textView" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="" android:id="@+id/autore" android:inputType="textNoSuggestions"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Genere" android:id="@+id/textView2" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="PENE" android:id="@+id/genere" android:inputType="textNoSuggestions"/> </LinearLayout> </RelativeLayout> </android.support.v7.widget.CardView> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:orientation="horizontal" android:layout_below="@+id/scheda" card_view:cardCornerRadius="5dp" card_view:cardUseCompatPadding="true" android:elevation="1dp"> <android.support.v7.widget.RecyclerView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/recyclerVolumi" /> </android.support.v7.widget.CardView> <com.getbase.floatingactionbutton.FloatingActionsMenu android:id="@+id/multiple_actions" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" fab:fab_addButtonColorNormal="@color/myPrimaryColor" fab:fab_addButtonColorPressed="@color/myPrimaryDarkColor" fab:fab_addButtonPlusIconColor="@color/white" fab:fab_labelStyle="@style/menu_labels_style" android:layout_marginBottom="16dp" android:layout_marginRight="16dp" android:layout_marginEnd="16dp" android:elevation="2dp"> <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/action_a" android:layout_width="wrap_content" android:layout_height="wrap_content" fab:fab_colorNormal="@color/white" fab:fab_title="Edit Comic" fab:fab_colorPressed="@color/white_pressed"/> <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/action_b" android:layout_width="wrap_content" android:layout_height="wrap_content" fab:fab_colorNormal="@color/white" fab:fab_title="Edit Volumi" android:onClick="volumi" fab:fab_colorPressed="@color/white_pressed"/> </com.getbase.floatingactionbutton.FloatingActionsMenu> </RelativeLayout> </ScrollView>

Answer1:

I think what you want to do is inflate different types of views in a RecyclerView rather than making a CardView + RecyclerView. <a href="https://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type" rel="nofollow">This SO question</a> was very helpful for me to start with.

<?xml version="1.0" encoding="utf-8"?> <FrameLayout... > <android.support.v7.widget.RecyclerView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/recyclerVolumi" /> <com.getbase.floatingactionbutton.FloatingActionsMenu android:id="@+id/multiple_actions"> <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/action_a"/> <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/action_b"/> </com.getbase.floatingactionbutton.FloatingActionsMenu> </Frame...>

So the first item of your RecyclerView will have the book details type view and the rest of the items will have list of books type view..

Recommend

  • Map and Cardview Activities
  • Push Up Fragment content when keyboard is activated
  • ScrollView adds extra space on top
  • Issue Filling Parent View When Inflating Linear Layout
  • Gallery Image File Exists but Bitmap decode file is null
  • Layout for Fragment overlapping Toolbar
  • Android FAB icon always black with MaterialComponents theme
  • AppBarLayout + NestedScrollView + RecyclerView won't scroll
  • Getting Fabric Python Library to Work
  • Simultaneous accesses to 0x10f10df48, but modification requires exclusive access
  • I can't show LinearLayout at bottom to scroll view
  • How to Update UILabel from Another ViewController
  • Dynamically creating HTML button control and nesting i tag within it
  • UIPageViewController delegate method similar to scrollViewDidScroll:(UIScrollview*)scrollview
  • Setting attributes of an EditText added dynamically in Android
  • Android Custom dialog inflating from layout - alignment issue
  • EditText ignores the ImeActionLabel
  • Toolbar shifts up, when soft keyboard appears
  • Gray line inside cardview :)?
  • I have two activity.I want to Send the data from second activity to previous activity.First activity
  • Custom WebViewPage inject code when razor template is rendering
  • Unable to resolve Static method?
  • Activity overlaying. WindowManager.LayoutParams
  • chrome video src change not working
  • How to get listview position?
  • Syntax error on tokens, AnnotationName expected instead - error on query
  • WPF version of .ScaleControl?
  • Hibernate to update table schema
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Jackson Parser: ignore deserializing for type mismatch
  • Change multiple background-images with jQuery
  • Trying to switch camera back to front but getting exception
  • jquery mobile loadPage not working
  • align graphs with different xlab
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How to stop GridView from loading again when I press back button?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize