日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

双重ScrollView,RecyclerView联动实例

發(fā)布時間:2025/3/21 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 双重ScrollView,RecyclerView联动实例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

最近收到一個需求,如圖,大家一看,不就是一個簡單的表格嗎,RecyclerView就搞定了

我一開始也是這么想的,但是當我繼續(xù)聽下去

需求是左邊黨支部欄目只能上下滑動,之后聯(lián)動右邊下方表格一起上下滑動,右邊下方表格滑動,左邊下方表格依然如此

然后右邊上方只能左右滑動,之后聯(lián)動右邊下方表格一起左右滑動,右下方滑動,右上同樣一起滑動

然后此時我的內(nèi)心是崩潰的

收集幾個關(guān)鍵點吧

1:右下方部分既能左右滑動,又可以上下滑動

2:左上角就是一個TextView,不動

3:需要對RecyclerView進行聯(lián)動

4:ListView應(yīng)該也可以實現(xiàn),但是我使用了擴展性更好的RecyclerView

5:RecyclerView不可以既左右滑動,又上下滑動,即他只能支持一個方向

所以基本有思路了

RecyclerView放在ScrollView容器內(nèi),上下滑動做RecyclerView聯(lián)動

左右滑動做ScrollView聯(lián)動

下面看xml layout代碼吧

<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:orientation="vertical"android:layout_height="match_parent"><LinearLayoutandroid:layout_width="match_parent"android:gravity="center_vertical"android:layout_height="40dp"><LinearLayoutandroid:gravity="center"android:layout_width="120dp"android:background="@color/gray_trans"android:layout_height="match_parent"><TextViewandroid:layout_marginStart="16dp"android:layout_marginEnd="16dp"android:text="黨支部"android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout><demo.MyScrollViewandroid:id="@+id/scrollView_right_up"android:layout_width="match_parent"android:scrollbars="none"android:layout_height="wrap_content"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><demo.MyRecyclerViewandroid:id="@+id/recyclerview_right_up"android:layout_width="match_parent"android:layout_height="40dp"></demo.MyRecyclerView></RelativeLayout></demo.MyScrollView></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><android.support.v7.widget.RecyclerViewandroid:id="@+id/recyclerview_left_bottom"android:layout_width="119dp"android:layout_height="match_parent"></android.support.v7.widget.RecyclerView><Viewandroid:background="@color/gray_trans"android:layout_width="1dp"android:layout_height="match_parent"/><demo.MyScrollViewandroid:id="@+id/scrollView"android:layout_width="wrap_content"android:layout_height="match_parent"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><demo.MyRecyclerViewandroid:id="@+id/recyclerview_right_bottom"android:layout_width="match_parent"android:layout_height="match_parent"></demo.MyRecyclerView></RelativeLayout></demo.MyScrollView></LinearLayout></LinearLayout>

其中MyScrollView是重寫的暴露了onScrollChanged 方法,之后我們可以setOnScrollListener對其滑動進行監(jiān)聽

MyRecyclerView重寫以及為什么要套一層RelativeLayout請看我上一篇文章解釋

?然后放出關(guān)鍵的聯(lián)動滑動代碼吧

public void setOnScrollLowSdk(){recyclerViewLeftBottom.addOnScrollListener(new RecyclerView.OnScrollListener() {@Overridepublic void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {if(recyclerView.getScrollState()!= RecyclerView.SCROLL_STATE_IDLE){recyclerViewRightBottom.scrollBy(dx, dy);}}});recyclerViewRightBottom.addOnScrollListener(new RecyclerView.OnScrollListener() {@Overridepublic void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {if(recyclerView.getScrollState()!= RecyclerView.SCROLL_STATE_IDLE){recyclerViewLeftBottom.scrollBy(dx,dy);}}});scrollViewRB.setOnScrollListener(new MyScrollView.OnScrollListener() {@Overridepublic void onScroll(int scorllX, int scrollY, int oldX, int oldY) {scrollViewRU.scrollTo(scorllX,scrollY);}});scrollViewRU.setOnScrollListener(new MyScrollView.OnScrollListener() {@Overridepublic void onScroll(int scorllX, int scrollY, int oldX, int oldY) {scrollViewRB.scrollTo(scorllX,scrollY);}});}

命名的話應(yīng)該可以看懂RU代表RightUp右上方,RB代表RightBottom右下方

至此就可以了,省去了RecyclerView數(shù)據(jù)填充以及各種的LayoutManager初始化,這個也不難

就搞定了

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/fengfenghuifei/p/10602583.html

總結(jié)

以上是生活随笔為你收集整理的双重ScrollView,RecyclerView联动实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。