gpt4 book ai didi

android - 如何在 RecyclerView 中获取位于当前屏幕底部的元素的位置?

转载 作者:行者123 更新时间:2023-11-29 14:58:55 27 4
gpt4 key购买 nike

我是 Android 的初学者,令人惊讶的是我没有在网上找到解决这个问题的方法。

我在 RecyclerView 中有 1 个 TextView (问题),我正在使用适配器将 n 个问题绑定(bind)到其中。

假设我在recyclerView中总共有20个问题,如何获取当前屏幕底部元素的位置(不是最后一个问题,而是当前屏幕底部问题的位置加载 View 时的屏幕)?

问题的长度将是动态的,因此第 n 个相同的问题不会在第一次加载时出现在屏幕底部。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="15dp"
android:focusable="true"
android:orientation="vertical">

<TextView
android:id="@+id/questionviewelement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:fontFamily="@font/opensans_semibold"
android:textColor="@color/color_question"
android:textSize="@dimen/settings_act_box_question_font_size" />
</LinearLayout>

和recyclerview

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarThumbVertical="@color/white"
android:scrollbarSize="2.5dp"
android:fadeScrollbars="false"
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="75dp">
</android.support.v7.widget.RecyclerView>

任何帮助将不胜感激!谢谢!

最佳答案

您尝试过这行代码吗?

GridLayoutManager layoutManager = ((GridLayoutManager)mRecyclerView.getLayoutManager());
int lastVisiblePosition = layoutManager.findLastVisibleItemPosition();

关于android - 如何在 RecyclerView 中获取位于当前屏幕底部的元素的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52646910/

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