【发布时间】:2018-03-03 11:23:00
【问题描述】:
我有一个带有 nestedscrollview.inside 的布局,我有一个带有 2 个 recyclerview 和其他一些视图的相对布局。
我想将滚动监听器设置为回收器视图之一。我已经尝试过使用下面的代码,但它在嵌套的滚动视图中不起作用。
xml:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_deals_show"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/relativeLayoutId"
android:background="#015cb7"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Deal"
android:textColor="#f9f9f9"
android:textSize="18sp"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/searchButtonId"
android:src="@drawable/search"
android:layout_alignParentEnd="true"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:background="?android:attr/selectableItemBackground"
/>
</RelativeLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/adPostButtonId"
android:text="Post an ad"
android:background="#c44"
android:textColor="#f9f9f9"
android:layout_below="@+id/relativeLayoutId"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Featured Ad"
android:layout_below="@+id/adPostButtonId"
android:id="@+id/featuredTvId"
android:textSize="18sp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:textColor="#000000"
/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyclerViewId_featuredDeal"
android:background="#fdfbfb"
android:nestedScrollingEnabled="false"
android:layout_below="@+id/featuredTvId"
android:layout_marginTop="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Latest Ad"
android:layout_below="@+id/recyclerViewId_featuredDeal"
android:id="@+id/latestDealTvId"
android:layout_marginTop="30dp"
android:textSize="18sp"
android:padding="5dp"
android:textColor="#000000"
/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyclerViewId_deal"
android:background="#fdfbfb"
android:nestedScrollingEnabled="false"
android:layout_below="@+id/latestDealTvId"
android:layout_marginTop="10dp"
/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
我已经从活动中尝试过:
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (recyclerViewId_deal!=null && linearLayoutManager!=null){
visibleItemCount=recyclerViewId_deal.getChildCount();
totalItemCount=linearLayoutManager.getItemCount();
firstItem=linearLayoutManager.findFirstVisibleItemPosition();
if ((firstItem + visibleItemCount >= totalItemCount) && firstItem > 0 && oldScrollY > 0 && !scrollCheck) {
dealListShow(pageNo);
scrollCheck = true;
}
}
}
});
但是我的滚动监听器不能在nestedscroll 视图中工作,但在没有nestedscrollview 的情况下工作良好。我尝试了一些 SO 解决方案但没有奏效,有没有办法在嵌套的滚动视图中做滚动监听器
【问题讨论】:
标签: android android-recyclerview android-nestedscrollview