Giter Site home page Giter Site logo

pinnedheaderexpandablelistview's Introduction

PinnedHeaderExpandableListView

##前言 Android中,大家都用过ListView,ExpandableListView等,也许你还用过PinnedHeaderListView,但是如果我说PinnedHeaderExpandableListView,你听过吗?还有可下拉的PinnedHeaderExpandableListView呢?没听过也不要紧,本文就是介绍这个东西的,为了让大家有更直观的了解,先上效果图。通过效果图可以看出,首先它是一个ExpandableListView,但是它的头部可以固定,其次,在它的上面还有一个头部可以来回伸缩,恩,这就是本文要介绍的自定义view。为了提高复用性,这个效果我分成来了2个view来实现,第一个是PinnedHeaderExpandableListView来实现头部固定的ExpandableListView,第二个view是StickyLayout,这个view具有一个可以上下滑动的头部,最后将这2个view组合在一起,就达到了如下的效果。

mahua

##接口

    public interface OnHeaderUpdateListener {
        /**
         * 返回一个view对象即可
         * 注意:view必须要有LayoutParams
         */
        public View getPinnedHeader();

        public void updatePinnedHeader(View headerView, int firstVisibleGroupPos);
    }
    
    public interface OnGiveUpTouchEventListener {
        public boolean giveUpTouchEvent(MotionEvent event);
    }

##如何使用 让你的activity实现OnHeaderUpdateListener, OnGiveUpTouchEventListener两个接口, 分别为PinnedHeaderExpandableListView中如何绘制和更新固定的头部以及StickyLayout中content何时放弃事件处理。

    @Override
    public View getPinnedHeader() {
        View headerView = (ViewGroup) getLayoutInflater().inflate(R.layout.group, null);
        headerView.setLayoutParams(new LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        return headerView;
    }

    @Override
    public void updatePinnedHeader(View headerView, int firstVisibleGroupPos) {
        Group firstVisibleGroup = (Group) adapter.getGroup(firstVisibleGroupPos);
        TextView textView = (TextView) headerView.findViewById(R.id.group);
        textView.setText(firstVisibleGroup.getTitle());
    }

    @Override
    public boolean giveUpTouchEvent(MotionEvent event) {
        if (expandableListView.getFirstVisiblePosition() == 0) {
            View view = expandableListView.getChildAt(0);
            if (view != null && view.getTop() >= 0) {
                return true;
            }
        }
        return false;
    }

##许可协议 采用MIT共享协议发布 ##更详细的介绍 可下拉的PinnedHeaderExpandableListView的实现

pinnedheaderexpandablelistview's People

Contributors

singwhatiwanna avatar

Watchers

James Cloos avatar star cheng avatar

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.