【发布时间】:2021-10-28 04:25:49
【问题描述】:
我正在制作应用程序,但找不到任何解决方案。这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@color/DarkGray"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/BackGroundColor"
android:orientation="horizontal"
android:paddingTop="4dp"
android:paddingBottom="4dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="@color/SecondaryTextColor"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="@color/SecondaryTextColor"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@color/BlueGray"
android:nestedScrollingEnabled="false"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/BackGroundColor"
android:padding="4dp"
android:textAlignment="center"
android:textColor="@color/PrimaryTextColor"
android:textSize="22sp" />
<ListView
android:id="@+id/eventsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
我想要实现的是在我的 ListView 中添加 CardViews,并且不仅可以滚动 ListView,还可以滚动整个视图。我之前尝试过 RecyclerView,但这对我也不起作用。
这是我的想法:
并滚动整个内容,而不仅仅是 ListView。
【问题讨论】:
-
第 2 课:不要将 ListView 放在 ScrollView 中。
-
如果不是我可以使用的 RecyclerView 或 ListView,我应该使用什么来存储多个用户添加的 CardView?
-
你应该使用 NestedScrollView。
标签: java android android-studio listview scrollview