【发布时间】:2020-07-19 10:54:48
【问题描述】:
这是我的代码-
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/frame1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:text="Recruitment Responses"
android:gravity="center"
android:textSize="30sp"
android:textColor="#fff"
android:background="@drawable/bg_rounded1"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/frame1"
android:background="#f9fafc"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
滚动不流畅,很烦人,有什么办法可以改善吗?我希望 textview 在向上滚动时与 Recycler View 一起上升,这就是为什么我将它们都嵌套在 ScrollView 中的原因,也许这就是造成问题的原因!
【问题讨论】:
-
嵌套在同一方向(水平/垂直)滚动的视图通常不是一个好主意。
-
尝试使用 CoordinatorLayout、CollapsibleToolbar 来实现该行为。如果您有大量项目,则使用高度设置为
wrap_content的回收站视图不是一个好主意。
标签: java android xml android-recyclerview android-scrollview