Giter VIP home page Giter VIP logo

Comments (3)

zhaozhentao avatar zhaozhentao commented on September 13, 2024

recyclerView的接入有需要的话可以研究下,从实现的原理上决定了要采用这种布局

from inboxlayout.

xcc3641 avatar xcc3641 commented on September 13, 2024

同样感兴趣该项目如何使用RecyclerView替换ListView

from inboxlayout.

yangbo637829 avatar yangbo637829 commented on September 13, 2024

package com.zzt.inbox.widget;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;

/**

  • Created by me on 17-1-19.
    */

public class InboxLayoutRecyclerView extends InboxLayoutBase {
private RecyclerView dragableView;

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

public InboxLayoutRecyclerView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
}

public InboxLayoutRecyclerView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected RecyclerView createDragableView(Context context, AttributeSet attrs) {
    dragableView = new RecyclerView(context);
    dragableView.setId(android.R.id.list);
    dragableView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    return dragableView;
}

public void setAdapter(RecyclerView.Adapter adapter) {
    dragableView.setAdapter(adapter);
}

protected boolean isReadyForDragStart() {
    final RecyclerView.Adapter adapter = dragableView.getAdapter();
    if (null == adapter || adapter.getItemCount() == 0) {
        return true;
    } else {
        if (getFirstVisiblePosition() <= 1) {
            final View firstVisibleChild = dragableView.getChildAt(0);
            if (firstVisibleChild != null) {
                return firstVisibleChild.getTop() >= dragableView.getTop();
            }
        }
    }
    return false;
}

protected boolean isReadyForDragEnd() {
    final RecyclerView.Adapter adapter = dragableView.getAdapter();

    if (null == adapter || adapter.getItemCount() == 0) {
        return true;
    } else {
        final int lastItemPosition = getCount() - 1;
        final int lastVisiblePosition = getLastVisiblePosition();
        if (lastVisiblePosition >= lastItemPosition - 1) {
            final int childIndex = lastVisiblePosition - getFirstVisiblePosition();
            final View lastVisibleChild = dragableView.getChildAt(childIndex);
            if (lastVisibleChild != null) {
                return lastVisibleChild.getBottom() <= dragableView.getBottom();
            }
        }
    }
    return false;
}

private int getFirstVisiblePosition() {
    if (dragableView != null) {
        RecyclerView.LayoutManager layoutManager = dragableView.getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            return ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
        }
    }
    return -1;
}

private int getCount() {
    if (dragableView != null) {
        RecyclerView.LayoutManager layoutManager = dragableView.getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            return layoutManager.getItemCount();
        }
    }
    return 0;
}

private int getLastVisiblePosition() {
    if (dragableView != null) {
        RecyclerView.LayoutManager layoutManager = dragableView.getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            return ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
        }
    }
    return -1;
}

}

from inboxlayout.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.