有这个标记:
<?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=".pollsModule.PollsScr">
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="3dp"
android:background="@color/colorAccent" />
<TextView
android:id="@+id/intro_text_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="10dp"
android:textAlignment="center"
android:visibility="gone" />
<TextView
android:id="@+id/intro_text_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/intro_text_header"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:visibility="gone" />
<Button
android:id="@+id/next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/main_screen_btn"
android:visibility="gone" />
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:layout_below="@id/divider">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/question_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:fontFamily="@font/opensans_semibold"
android:textColor="#666666"
android:visibility="gone"
app:autoSizeMaxTextSize="18sp"
app:autoSizeMinTextSize="14sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform" />
<EditText
android:id="@+id/user_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/question_text"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:fontFamily="@font/opensans_semibold"
android:textColor="#666666"
android:visibility="gone" />
<ImageView
android:id="@+id/questionImg"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="QuestionImg"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/answerOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/user_input"
android:layout_marginStart="5dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"
android:overScrollMode="never"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<LinearLayout
android:id="@+id/question_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/answerOptions"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="20">
<Button
android:id="@+id/prev_question"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="10"
android:text="@string/previous_question_polls" />
<Button
android:id="@+id/next_question"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="10"
android:background="@drawable/main_screen_btn"
android:text="@string/next_question_polls"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
并且有一个这样的列表:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/answerOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/user_input"
android:layout_marginStart="5dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"
android:overScrollMode="never"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
在此列表中,在某些条件下,元素可以具有以下标记:
<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/question_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:textColor="#666666"
app:autoSizeMaxTextSize="16sp"
app:autoSizeMinTextSize="12sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/answerOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/question_text"
android:layout_marginStart="5dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</RelativeLayout>
简单来说,一个list里面会有几个list:
NestedScrollView
- RecyclerView_1
-- LinearLayout
--- RecyclerView_2
我不确定我描绘的是否正确,但我试图把它描绘清楚))问题的本质:例如,列表中有RecyclerView_1
3 个元素,3 个列表中的每一个RecyclerView_2
都有 6 个元素。例如,如果我们单击位于我RecyclerView_2
的位置 2的元素之一或滚动到最顶部。我无法弄清楚可能是什么问题。我想制作 smoothScrollTo 但它没有帮助。RecyclerView_1
NestedScrollView
RecyclerView_1
没想到,当我在 Google 中正确制定查询时,我找到了一种解决方案))您需要在
RelativeLayout
其中添加NestedScrollView
以下行:这是我找到此解决方案的地方。