0

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:

Android application screenshot

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>
Mike dg
  • 4,648
  • 2
  • 27
  • 26
  • You should never put a scrollable view (recycler) inside another scrollable view (scrollview). Make a single recyclerview without scrollview and put Author info as a header to it. – poss Aug 03 '15 at 14:19

1 Answers1

0

I think what you want to do is inflate different types of views in a RecyclerView rather than making a CardView + RecyclerView. This SO question 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..

Community
  • 1
  • 1
Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41