从带有SwipeToRefresh布局的ViewPager适配器中的CardList的RecycleView中获取scrollY属性

亚历克斯

好的,所以我想从我的RecycleView中获取scrollY属性(以查看我在CardList中滚动的位置。我有以下设置

首先,主要活动,其中包含一个SlidingTabs布局,其子元素为SwipeToFresh布局,以及两个选项卡片段的ViewPager,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.popal.soul.MovieListActivity">

<com.example.popal.soul.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:background="@color/ColorPrimary"/>


<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipeContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1">

    </android.support.v4.view.ViewPager>

</android.support.v4.widget.SwipeRefreshLayout>


</LinearLayout>

然后我让每个片段都具有相同的布局,像这样,并带有RecycleView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/cardList"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
</RelativeLayout>

最后是RecycleView的每张卡的布局(我不认为这很重要,但是我还是会添加它)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?android:attr/selectableItemBackground">
    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:background="@color/bkg_card"
        android:text="Movie Title"
        android:gravity="center_vertical"
        android:textColor="@android:color/white"
        android:textSize="14dp"/>

    <ImageView
        android:elevation="5dp"
        android:scaleType="fitCenter"
        android:layout_width="100dp"
        android:layout_height="150dp"
        android:id="@+id/imageViewPoster"
        android:text="Poster"
        android:gravity="center_vertical"
        android:layout_below="@id/title"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="5dp"/>

    <ImageView
        android:id="@+id/imageViewFanart"
        android:scaleType="fitCenter"
        android:layout_alignBottom="@+id/imageViewPoster"
        android:layout_toEndOf="@+id/imageViewPoster"
        android:layout_width= "235dp"
        android:layout_height="122dp"
        android:layout_marginRight="5dp"/>

 </RelativeLayout>

 </android.support.v7.widget.CardView>

现在,我试图从定义SwipeToRefresh布局的主活动中获取RecycleView项的滚动位置。我需要执行此操作来解决有关SwipeToRefresh布局中的错误的变通方法,尝试从列表底部向上滚动会触发刷新调用:SwipeRefreshLayout + WebView,当滚动位置位于顶部时,但是如您所见,两种解决方案都需要访问同一类或活动中的“刷卡容器”和“ RecycleView”。

我尝试使用类似的东西 int scrollY = pager.getChildAt(pager.getCurrentItem()).getScrollY();

从理论上讲,它应该返回子项的位置(在本例中为RecycleView),但它仍返回0(添加的日志条目以在滚动状态发生变化时获取实时事件),就像if仍在返回的位置一样。 ViewPage适配器。

有人有想法吗?

MH。

如先前的评论所述:您可以定义一个简单的侦听器接口,托管活动将实现该接口,然后各个片段可以通过它们RecyclerView(从它们自己的local OnScrollListener传递其滚动位置

与片段进行通信的这一概念描述在这里更详细地一些示例代码

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

片段的ViewPager中的Listview适配器-如何获取活动

来自分类Dev

如何在recycleview适配器中设置布局可见性,我的适配器代码是

来自分类Dev

从ViewPager中的片段调用适配器

来自分类Dev

从ViewPager中的片段调用适配器

来自分类Dev

在适配器中膨胀不同的布局

来自分类Dev

带有arraylist的listview,android中的简单适配器

来自分类Dev

如何从适配器设置 startActivityForResult 并在 viewPager 片段中获取结果

来自分类Dev

如何获取在 recyclerview 适配器中尚不可见的布局管理器的子项?

来自分类Dev

Android:从viewPager中的Fragment调用ListView的适配器的getview()

来自分类Dev

在 viewpager 重新加载适配器中强制片段

来自分类Dev

Fragments 中的 Recyclerview,跳过未附加适配器的布局

来自分类Dev

Recycleview RecyclerView:未连接适配器;跳过布局

来自分类Dev

没有连接适配器;跳过片段中的布局错误

来自分类Dev

适配器中的ArrayList?

来自分类Dev

Android Studio中带有自定义适配器的自定义ListView

来自分类Dev

为什么onStopTrackingTouch不能在带有seekbar的自定义适配器中工作?

来自分类Dev

带有片段中的自定义适配器的ListView

来自分类Dev

如何在Android中为带有图像的列表视图设置适配器

来自分类Dev

无线Broadcom适配器在带有内核4.2的Ubuntu 14.04中不起作用

来自分类Dev

带有 LiveData 的房间:适配器中的多对多映射

来自分类Dev

在 BizTalk 中自动化 JMS 适配器属性

来自分类Dev

如何从Android中的RecyclerView适配器获取物品

来自分类Dev

如何在Hubot脚本中获取适配器名称?

来自分类Dev

在阵列适配器中获取ListView的宽度

来自分类Dev

在RecyclerView的适配器中获取上下文

来自分类Dev

如何从Android Kotlin中的RecyclerView适配器获取arraylist

来自分类Dev

在Windows 7中获取无线适配器的频带模式

来自分类Dev

如何在Hubot脚本中获取适配器名称?

来自分类Dev

在适配器中获取多个数据单元getView()

Related 相关文章

  1. 1

    片段的ViewPager中的Listview适配器-如何获取活动

  2. 2

    如何在recycleview适配器中设置布局可见性,我的适配器代码是

  3. 3

    从ViewPager中的片段调用适配器

  4. 4

    从ViewPager中的片段调用适配器

  5. 5

    在适配器中膨胀不同的布局

  6. 6

    带有arraylist的listview,android中的简单适配器

  7. 7

    如何从适配器设置 startActivityForResult 并在 viewPager 片段中获取结果

  8. 8

    如何获取在 recyclerview 适配器中尚不可见的布局管理器的子项?

  9. 9

    Android:从viewPager中的Fragment调用ListView的适配器的getview()

  10. 10

    在 viewpager 重新加载适配器中强制片段

  11. 11

    Fragments 中的 Recyclerview,跳过未附加适配器的布局

  12. 12

    Recycleview RecyclerView:未连接适配器;跳过布局

  13. 13

    没有连接适配器;跳过片段中的布局错误

  14. 14

    适配器中的ArrayList?

  15. 15

    Android Studio中带有自定义适配器的自定义ListView

  16. 16

    为什么onStopTrackingTouch不能在带有seekbar的自定义适配器中工作?

  17. 17

    带有片段中的自定义适配器的ListView

  18. 18

    如何在Android中为带有图像的列表视图设置适配器

  19. 19

    无线Broadcom适配器在带有内核4.2的Ubuntu 14.04中不起作用

  20. 20

    带有 LiveData 的房间:适配器中的多对多映射

  21. 21

    在 BizTalk 中自动化 JMS 适配器属性

  22. 22

    如何从Android中的RecyclerView适配器获取物品

  23. 23

    如何在Hubot脚本中获取适配器名称?

  24. 24

    在阵列适配器中获取ListView的宽度

  25. 25

    在RecyclerView的适配器中获取上下文

  26. 26

    如何从Android Kotlin中的RecyclerView适配器获取arraylist

  27. 27

    在Windows 7中获取无线适配器的频带模式

  28. 28

    如何在Hubot脚本中获取适配器名称?

  29. 29

    在适配器中获取多个数据单元getView()

热门标签

归档