Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android RecyclerView在RelativeLayout中未正确滚动_Java_Android_Android Layout - Fatal编程技术网

Java Android RecyclerView在RelativeLayout中未正确滚动

Java Android RecyclerView在RelativeLayout中未正确滚动,java,android,android-layout,Java,Android,Android Layout,我正在制作一个android应用程序,它有一个活动,用户可以选择要生成的随机数,然后显示这些数字。这都在一个relativeLayout中,它内部有一个ScrollView。在滚动视图中,有一个静态的cardwiew,用户在其中选择所需的号码,然后单击按钮生成并显示在静态cardwiew下方的RecyclerView(动态创建用户选择的相同号码的cardwiew)。除了动态添加的cardwiew之间的滚动和间距之外,我的所有功能都正常工作。Recylerview中的cardwiews的间距很大

我正在制作一个android应用程序,它有一个活动,用户可以选择要生成的随机数,然后显示这些数字。这都在一个
relativeLayout
中,它内部有一个
ScrollView
。在滚动视图中,有一个静态的
cardwiew
,用户在其中选择所需的号码,然后单击按钮生成并显示在静态
cardwiew
下方的
RecyclerView
(动态创建用户选择的相同号码的
cardwiew
)。除了动态添加的
cardwiew
之间的滚动和间距之外,我的所有功能都正常工作。
Recylerview
中的
cardwiews
的间距很大

以下是该问题的屏幕截图:

My CardView项目布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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="match_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/LottoNumberGenerator_Numbers"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        card_view:cardCornerRadius="2dp"
        card_view:contentPadding="10dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/LottoNumberGenerator_NumbersHeading"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toStartOf="@+id/LottoNumberGenerator_Menu"
                android:gravity="center_horizontal"
                android:text="Number Combination #1"
                android:textAppearance="@style/TextAppearance.AppCompat.Large"
                android:textColor="@color/colorPrimary"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/LottoNumberGenerator_Menu"
                android:layout_width="20dp"
                android:layout_height="30dp"
                android:layout_alignParentRight="true"
                android:layout_margin="5dp"
                android:scaleType="centerCrop"
                android:src="@drawable/ic_dots"/>

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/LottoNumberGenerator_Menu">

                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:id="@+id/LottoNumberGenerator_Number1"
                        android:layout_width="0dp"
                        android:layout_height="50dp"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@drawable/number_red"
                        android:gravity="center"
                        android:text="10"
                        android:textSize="24sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/LottoNumberGenerator_Number2"
                        android:layout_width="0dp"
                        android:layout_height="50dp"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@drawable/number_green"
                        android:gravity="center"
                        android:text="30"
                        android:textSize="24sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/LottoNumberGenerator_Number3"
                        android:layout_width="0dp"
                        android:layout_height="50dp"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@drawable/number_blue"
                        android:gravity="center"
                        android:text="50"
                        android:textSize="24sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/LottoNumberGenerator_Number4"
                        android:layout_width="0dp"
                        android:layout_height="50dp"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@drawable/number_yellow"
                        android:gravity="center"
                        android:text="70"
                        android:textSize="24sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/LottoNumberGenerator_Number5"
                        android:layout_width="0dp"
                        android:layout_height="50dp"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@drawable/number_red"
                        android:gravity="center"
                        android:text="90"
                        android:textSize="24sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/LottoNumberGenerator_Number6"
                        android:layout_width="0dp"
                        android:layout_height="50dp"
                        android:layout_margin="2dp"
                        android:layout_weight="1"
                        android:background="@drawable/number_yellow"
                        android:gravity="center"
                        android:text="99"
                        android:textSize="24sp"
                        android:textStyle="bold" />
                </TableRow>

            </TableLayout>

            <Space
                android:layout_width="1dp"
                android:layout_height="10dp" />

        </RelativeLayout>

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

</RelativeLayout>

我的主要活动代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_lotto_number_generator">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/Generator_BannerAd"
        android:layout_alignParentStart="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_marginBottom="10dp">

            <android.support.v7.widget.CardView
                android:id="@+id/Generator_Lines"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="5dp"
                card_view:cardCornerRadius="2dp"
                card_view:contentPadding="10dp">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/Generator_LinesHeading"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:text="Numbers Wanted?"
                        android:textAppearance="@style/TextAppearance.AppCompat.Large"
                        android:textColor="@color/colorPrimary"
                        android:textStyle="bold" />

                    <TableLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/Generator_LinesHeading">

                        <TableRow
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <Button
                                android:id="@+id/Generator_LinesMinus"
                                android:layout_width="0dp"
                                android:layout_height="100dp"
                                android:layout_gravity="center_vertical|center_horizontal"
                                android:layout_margin="5dp"
                                android:layout_weight="1"
                                android:background="@drawable/button"
                                android:gravity="center_vertical"
                                android:padding="0dp"
                                android:text="-"
                                android:textAlignment="center"
                                android:textColor="@color/colorPrimaryDark"
                                android:textSize="55sp"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/Generator_LinesAmount"
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_margin="5dp"
                                android:layout_weight="1"
                                android:gravity="center_vertical|center_horizontal"
                                android:text="1"
                                android:textAlignment="center"
                                android:textColor="@color/colorPrimaryDark"
                                android:textSize="60sp"
                                android:textStyle="bold" />

                            <Button
                                android:id="@+id/Generator_LinsPlus"
                                android:layout_width="0dp"
                                android:layout_height="100dp"
                                android:layout_gravity="center_vertical|center_horizontal"
                                android:layout_margin="5dp"
                                android:layout_weight="1"
                                android:background="@drawable/button"
                                android:gravity="center_vertical"
                                android:padding="0dp"
                                android:text="+"
                                android:textAlignment="center"
                                android:textColor="@color/colorPrimaryDark"
                                android:textSize="55sp"
                                android:textStyle="bold" />

                        </TableRow>

                        <TableRow>

                            <Button
                                android:id="@+id/Generator_Generate"
                                android:layout_width="0dp"
                                android:layout_height="50dp"
                                android:layout_margin="5dp"
                                android:layout_weight="1"
                                android:background="@drawable/button"
                                android:text="Generate Numbers"
                                android:textColor="@color/colorPrimaryDark"
                                android:textSize="18sp" />

                        </TableRow>

                    </TableLayout>

                    <Space
                        android:layout_width="1dp"
                        android:layout_height="10dp" />

                </RelativeLayout>

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/Generator_RecyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/Generator_Lines"
                android:scrollbars="none">

            </android.support.v7.widget.RecyclerView>

        </RelativeLayout>

    </ScrollView>

    <LinearLayout
        android:id="@+id/Generator_BannerAd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:layout_marginTop="5dp"></LinearLayout>

</RelativeLayout>


这可能非常简单。我认为正在发生的是,由于您的
CardView
中的RelativeLayout的高度为
match\u parent
,因此它将CardView的高度与整个布局的高度相匹配。如果您将其更改为
wrap\u content
,它将解决您的问题。

在项目布局的6行中替换

android:layout_height="match_parent"


将cardview和recyclerview高度的父布局更改为
wrap\u content
此注释不会解决您的问题。然而,我注意到的是,你有一个
RelativeLayout
然后是一个'ScrollView',然后又是一个'RelativeLayout',你为什么不把
ScrollView
作为你的根布局呢?另外,把你的
ScrollView
改成
NestedScrollView
,因为你有一个
ScrollView
和'RecyclerView'。
android:layout_height="wrap_content"