gpt4 book ai didi

java - Android RecyclerView 内的relativelayout 无法正确滚动

转载 作者:行者123 更新时间:2023-12-02 11:50:25 25 4
gpt4 key购买 nike

我正在制作一个Android应用程序,它有一个 Activity ,用户可以选择要生成多少个随机数,然后显示这些数字。这一切都在一个 RelativelLayout 内,其中有一个 ScrollView 。在 ScrollView 中,有一个静态的 CardView,用户可以在其中选择他们想要的数字,然后单击一个按钮,该按钮将生成并在 RecyclerView 中显示它(动态创建与用户选择的 CardView 数量相同。)位于静态 CardView 下方。除了动态添加的 CardView 之间的滚动和间距之外,我一切正常。 Recylerview 中的 CardViews 不知何故间距很大。

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

Below is a screenshot of the issue:

我的 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>

我的主要 Activity 代码:

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

最佳答案

在项目布局的第6行中替换

android:layout_height="match_parent"

android:layout_height="wrap_content"

关于java - Android RecyclerView 内的relativelayout 无法正确滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47914260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com