Ale*_*iun 1 android android-recyclerview
我有两个Recyclerview里面NestedScrollView.第二个Recyclerview也有SwipeRefreshLayout.我尝试为两个回收器设置一个滚动,但我的解决方案不起作用.两个回收器分开滚动,我没有解决方案,请帮助我.提前致谢.我的代码
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/noFriendsTitle"
android:layout_marginTop="@dimen/marginTop"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:text="@string/no_friends_title"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBarGetFriends"
android:layout_centerInParent="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainFriendsRelative"
android:paddingTop="@dimen/marginTopSmall"
android:paddingBottom="@dimen/marginTopSmall"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/paddingStart"
android:id="@+id/lastConversationTitle"
android:text="@string/friends_important_title"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lastChatFriendsRecyclerView"
android:layout_below="@+id/lastConversationTitle"
android:layout_marginTop="@dimen/marginTopSmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/paddingStart"
android:layout_below="@+id/lastChatFriendsRecyclerView"
android:layout_marginTop="@dimen/marginTopSmall"
android:id="@+id/allFriendsTitle"
android:text="@string/friends_all"/>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/friendSwipeToRefresh"
android:layout_below="@+id/allFriendsTitle"
android:layout_marginTop="@dimen/marginTopSmall">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/friendsRecyclerView"
android:scrollbars="vertical"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我的片段代码
private void setLastConversationFriendsRecycler(RecyclerView lastConversationRecyclerView, List<Edge<Friends>> friends){
lastConversationList.addAll(friends);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
lastConversationRecyclerView.setHasFixedSize(true);
lastConversationRecyclerView.setLayoutManager(layoutManager);
lastConversationAdapter = new FriendsAdapter(getActivity(), lastConversationList, lastConversationRecyclerView);
lastConversationRecyclerView.setAdapter(lastConversationAdapter);
}
private void setFriendsRecycler(RecyclerView friendsRecyclerView, List<Edge<Friends>> friends){
friendsList.addAll(friends);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
friendsRecyclerView.setHasFixedSize(true);
friendsRecyclerView.setLayoutManager(layoutManager);
friendsAdapter = new FriendsAdapter(getActivity(), friendsList, friendsRecyclerView);
friendsAdapter.setOnLoadMoreListener(friendsListener);
friendsRecyclerView.setAdapter(friendsAdapter);
}
Run Code Online (Sandbox Code Playgroud)
我也尝试不同的组合setNestedScrollingEnabled,但结果是一样的.
我已经找到了解决方案,并且我的代码出了什么问题.这是工作代码,也许有人有同样的问题.
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/friendSwipeToRefresh">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/noFriendsTitle"
android:layout_marginTop="@dimen/marginTop"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:text="@string/no_friends_title"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBarGetFriends"
android:layout_centerInParent="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainFriendsRelative"
android:paddingTop="@dimen/marginTopSmall"
android:paddingBottom="@dimen/marginTopSmall"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/paddingStart"
android:id="@+id/lastConversationTitle"
android:text="@string/friends_important_title"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lastChatFriendsRecyclerView"
android:layout_below="@+id/lastConversationTitle"
android:layout_marginTop="@dimen/marginTopSmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/paddingStart"
android:layout_below="@+id/lastChatFriendsRecyclerView"
android:layout_marginTop="@dimen/marginTopSmall"
android:id="@+id/allFriendsTitle"
android:text="@string/friends_all"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/friendsRecyclerView"
android:layout_marginTop="@dimen/marginTopSmall"
android:layout_below="@+id/allFriendsTitle" />
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
分段
private void setLastConversationFriendsRecycler(RecyclerView lastConversationRecyclerView, List<Edge<Friends>> friends){
lastConversationList.addAll(friends);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
lastConversationRecyclerView.setHasFixedSize(true);
lastConversationRecyclerView.setNestedScrollingEnabled(false);
lastConversationRecyclerView.setLayoutManager(layoutManager);
lastConversationAdapter = new FriendsAdapter(getActivity(), lastConversationList, lastConversationRecyclerView);
lastConversationRecyclerView.setAdapter(lastConversationAdapter);
}
private void setFriendsRecycler(RecyclerView friendsRecyclerView, List<Edge<Friends>> friends){
friendsList.addAll(friends);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
friendsRecyclerView.setHasFixedSize(true);
friendsRecyclerView.setNestedScrollingEnabled(false);
friendsRecyclerView.setLayoutManager(layoutManager);
friendsAdapter = new FriendsAdapter(getActivity(), friendsList, friendsRecyclerView);
friendsAdapter.setOnLoadMoreListener(friendsListener);
friendsRecyclerView.setAdapter(friendsAdapter);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2108 次 |
| 最近记录: |