第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

RecyclerView 實(shí)現(xiàn)瀑布流

標(biāo)簽:
Android

图片描述
http://idcbgp.cn/qadetail/91200 我在这个地址搜索到了,如何监听RecyclerView滑动到底的状态

之前hyman的RecyclerView课程也看了,当时实现完瀑布流后,就觉得滑动到底部时,最后一行的高度,没有占满外部View,感觉不太好。

既然是瀑布流,那么就选用StaggeredGridLayoutManager。
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL)); //纵向3列

/**
 * 实现了滑动到底部的处理,暂未添加自定义监听器
 * 实现了当LayoutManger是StaggeredGridLayoutManager时,滑到底部的那一行上的子view高度占满RecyclerView
 *
 * author : stone
 * email  : aa86799@163.com
 * time   : 16/5/6 14 23
 */
public class RichRecyclerView extends RecyclerView {

    private View mLastHasFocusView;
    private long mKeyTime;

    public RichRecyclerView(Context context) {
        this(context, null);
    }

    public RichRecyclerView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RichRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {
        super.onMeasure(widthSpec, heightSpec);
    }

    @Override
    public void onScrollStateChanged(int state) {
        if (state == RecyclerView.SCROLL_STATE_IDLE) {
            LayoutManager layoutManager = getLayoutManager();
            if (layoutManager instanceof StaggeredGridLayoutManager) {
                StaggeredGridLayoutManager lm = (StaggeredGridLayoutManager) layoutManager;
                int columnCount = lm.getColumnCountForAccessibility(null,null);
                int positions[] = new int[columnCount];
                lm.findLastVisibleItemPositions(positions);
                for (int i = 0; i < positions.length; i++) {
//                    System.out.println("当前视图上的最后可见列的位置" + positions[i]);
                }
                for (int i = 0; i < positions.length; i++) {
                    /**
                     * 判断lastItem的底边到recyclerView顶部的距离
                     * 是否小于recyclerView的高度
                     * 如果小于或等于 说明滚动到了底部
                     */
                    if (positions[i] >= lm.getItemCount() - columnCount) {
//                        System.out.println("滑动到底了1");

//                        System.out.println("总adapter的条目数:" + lm.getItemCount()); //内部取的adapter的方法
//                        System.out.println("总的列数:" + columnCount);
//                        System.out.println("符号条件的最后可见列上的position" + positions[i]);

                        ViewGroup.LayoutParams layoutParams = lm.findViewByPosition(positions[i]).getLayoutParams();
                        layoutParams.height = lm.findViewByPosition(positions[i]).getHeight() +
                                getHeight() - lm.findViewByPosition(positions[i]).getBottom();
                        lm.findViewByPosition(positions[i]).setLayoutParams(layoutParams);
                    }
                }
                int[] into = new int[columnCount];
                lm.findFirstCompletelyVisibleItemPositions(into);
                for (int i = 0; i < into.length; i++) {
                    System.out.println("首次完全可见的view位置:" + into[i]);
                }

                lm.findFirstVisibleItemPositions(into);
                for (int i = 0; i < into.length; i++) {
                    System.out.println("首次可见的view位置(即使部份可见):" + into[i]);
                }

            } else if (layoutManager instanceof LinearLayoutManager){
                LinearLayoutManager lm = (LinearLayoutManager) layoutManager;
                int position = lm.findLastVisibleItemPosition();
                if (position + 1 == lm.getItemCount()) {
                    System.out.println("滑动到底了2");

                }
            }
        }
        super.onScrollStateChanged(state);
    }
}
點(diǎn)擊查看更多內(nèi)容
5人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開(kāi)發(fā)工程師
手記
粉絲
10
獲贊與收藏
106

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消