安卓:滚动型和recyclerview [英] Android: scrollview and recyclerview

查看:270
本文介绍了安卓:滚动型和recyclerview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个应用程序,将列出所有Writer.The屏幕的本本有两个cardview:

第一种具有约作家信息,它将具有始终相同的高度。

第二个将有他的书的清单。我想第二张牌有无限的高度,即只要添加一本书,该卡将不再增长。

起初,我用了一个滚动视图为根,夸大了卡保存在数据库中每本书里面一排。
现在,我使用的是第二张牌内recyclerview,因为它帮助和简化了code。但现在我可以在卡内,而不是所有的屏幕上滚动,我不希望这种情况发生。我怎样才能解决呢?

第二张牌不应该是滚动:

Android应用程序截图

这是布局的XML

 <?XML版本=1.0编码=UTF-8&GT?;
<滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    的xmlns:FAB =htt​​p://schemas.android.com/apk/res-auto
    机器人:ID =@ + ID /滚动视图
    机器人:layout_centerVertical =真
    机器人:layout_centerHorizo​​ntal =真
    机器人:fillViewport =真
    机器人:nestedScrollingEnabled =真正的>    < RelativeLayout的
        机器人:方向=垂直的android:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT>
        < android.support.v7.widget.CardView的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_margin =5DP
            机器人:方向=横向
            card_view:cardCornerRadius =5DP
            card_view:cardUseCompatPadding =真
            机器人:ID =@ + ID / scheda>            <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                机器人:方向=垂直的android:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:填充=10dp>                <的LinearLayout
                    机器人:方向=垂直
                    机器人:layout_width =match_parent
                    机器人:layout_height =WRAP_CONTENT
                    机器人:layout_alignParentTop =真
                    机器人:layout_alignParentStart =真正的>                    <的TextView
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
                        机器人:文字=TITOLO
                        机器人:ID =@ + ID / textView3
                        机器人:知名度=水涨船高/>                    <的EditText
                        机器人:layout_width =FILL_PARENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
                        机器人:文字=
                        机器人:ID =@ + ID / TITOLO
                        机器人:知名度=水涨船高
                        安卓的inputType =textNoSuggestions/>                    <的TextView
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
                        机器人:文字=AUTORE
                        机器人:ID =@ + ID / TextView的/>                    <的EditText
                        机器人:layout_width =match_parent
                        机器人:layout_height =WRAP_CONTENT
                        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
                        机器人:文字=
                        机器人:ID =@ + ID / AUTORE
                        安卓的inputType =textNoSuggestions/>                    <的TextView
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT
                        机器人:textAppearance =机器人:ATTR / textAppearanceMedium
                        机器人:文字=Genere
                        机器人:ID =@ + ID / textView2/>                    <的EditText
                        机器人:layout_width =match_parent
                        机器人:layout_height =WRAP_CONTENT
                        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
                        机器人:文字=PENE
                        机器人:ID =@ + ID / genere
                        安卓的inputType =textNoSuggestions/>                < / LinearLayout中>            < / RelativeLayout的>        < /android.support.v7.widget.CardView>        < android.support.v7.widget.CardView的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_margin =5DP
            机器人:方向=横向
            机器人:layout_below =@ + ID / scheda
            card_view:cardCornerRadius =5DP
            card_view:cardUseCompatPadding =真
            机器人:海拔=1DP>            < android.support.v7.widget.RecyclerView
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT
                机器人:ID =@ + ID / recyclerVolumi/>        < /android.support.v7.widget.CardView>        < com.getbase.floatingactionbutton.FloatingActionsMenu
            机器人:ID =@ + ID / multiple_actions
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentBottom =真
            机器人:layout_alignParentRight =真
            机器人:layout_alignParentEnd =真
            FAB:fab_addButtonColorNormal =@彩色/ myPrimaryColor
            FAB:fab_addButtonColor pressed =@彩色/ myPrimaryDarkColor
            FAB:fab_addButtonPlusIconColor =@色/白
            FAB:fab_labelStyle =@风格/ menu_labels_style
            机器人:layout_marginBottom =16DP
            机器人:layout_marginRight =16DP
            机器人:layout_marginEnd =16DP
            机器人:海拔=2DP>            < com.getbase.floatingactionbutton.FloatingActionButton
                机器人:ID =@ + ID / action_a
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                FAB:fab_colorNormal =@色/白
                FAB:fab_title =编辑漫画
                FAB:fab_color pressed =@色/ white_ pressed/>            < com.getbase.floatingactionbutton.FloatingActionButton
                机器人:ID =@ + ID / action_b
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                FAB:fab_colorNormal =@色/白
                FAB:fab_title =编辑Volumi
                安卓的onClick =volumi
                FAB:fab_color pressed =@色/ white_ pressed/>        < /com.getbase.floatingactionbutton.FloatingActionsMenu>    < / RelativeLayout的>< /滚动型>


解决方案

我想你想要做的是膨胀不同类型的视图在 RecyclerView ,而不是让一个什么 CardView + RecyclerView 。 <一href=\"http://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type\">This SO质疑是非常有益的对我下手。

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;的FrameLayout ...&GT;
    &LT; android.support.v7.widget.RecyclerView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:ID =@ + ID / recyclerVolumi/&GT;    &LT; com.getbase.floatingactionbutton.FloatingActionsMenu
        机器人:ID =@ + ID / multiple_actions&GT;        &LT; com.getbase.floatingactionbutton.FloatingActionButton
            机器人:ID =@ + ID / action_a/&GT;        &LT; com.getbase.floatingactionbutton.FloatingActionButton
            机器人:ID =@ + ID / action_b/&GT;    &LT; /com.getbase.floatingactionbutton.FloatingActionsMenu>
&LT; /帧...&GT;

做的第一项你的 RecyclerView 将在本书的详细类型视图和项目的其余部分将有图书类型查看列表。

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:

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>

解决方案

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..

这篇关于安卓:滚动型和recyclerview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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