项目作者: AvinashChowdary

项目描述 :
The default Expandable ListView doesn't have animations. This component allows you to use a view combining Expandable ListView and Animation
高级语言: Java
项目地址: git://github.com/AvinashChowdary/AnimatedExpandableListView.git


Component : AnimatedExpandableListView
This document explains how to use the component

Classes to be Copied :
Copy the following classes from component folder

  • AnimatedExpandableListView
  • AnimatedExpandableListAdapter
  • DummyView
  • ExpandAnimation
  • GroupInfo

    Note : Current classes are in the package com.avinash.uihelper, these can either be copied to specified package or
    change them as per requirement.

AnimatedExpandableListView : is used for creating ExpandableListView with Expand and Collapse Animations

Usage :

In Layout:

  1. <com.avinash.uihelper.AnimatedExpandableListView
  2. android:id="@+id/expandable_lst"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@android:color/white"
  6. android:choiceMode="singleChoice"
  7. android:divider="@android:color/transparent"
  8. android:groupIndicator="@null"
  9. android:scrollbars="none"
  10. android:textColor="@android:color/black" ></com.avinash.uihelper.AnimatedExpandableListView>

In Activity/Fragment:

1) Make the Activity / Fragment implement

  1. * `ExpandableListView.OnGroupClickListener`
  2. * `ExpandableListView.OnChildClickListener`
  3. * `ExpandableListView.OnGroupExpandListener`

2) Usage

  1. ```java
  2. private AnimatedExpandableListView mExpandableListView;
  3. private ExpandableListAdapter mExpandableListAdapter;
  4. private int lastExpandedPosition = -1;
  5. ```
  6. ```java
  7. mExpandableListView = (AnimatedExpandableListView) findViewById(R.id.expandable_lst);
  8. mExpandableListAdapter = new ExpandableListAdapter(this, mGroupList, mChildList);
  9. mExpandableListView.setAdapter(mExpandableListAdapter);
  10. mExpandableListView.setOnGroupClickListener(this);
  11. mExpandableListView.setOnChildClickListener(this);
  12. mExpandableListView.setOnGroupExpandListener(this);
  13. ```
  14. ```java
  15. @Override
  16. public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
  17. if (mExpandableListView.isGroupExpanded(groupPosition)) {
  18. mExpandableListView.collapseGroupWithAnimation(groupPosition);
  19. } else {
  20. mExpandableListView.expandGroupWithAnimation(groupPosition);
  21. }
  22. return true;
  23. }
  24. @Override
  25. public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
  26. // handle click based on child position
  27. return false;
  28. }
  29. /**
  30. * This is done in order to close the previously expanded group
  31. * when clicked on a new group
  32. *
  33. *@param groupPosition
  34. */
  35. @Override
  36. public void onGroupExpand(int groupPosition) {
  37. if (lastExpandedPosition != -1
  38. && groupPosition != lastExpandedPosition) {
  39. mExpandableListView.collapseGroup(lastExpandedPosition);
  40. }
  41. lastExpandedPosition = groupPosition;
  42. }
  43. ```

3) Adapter

  1. * Extend your custom adapter with `AnimatedExpandableListAdapter`
  2. * Implement the methods
  3. ```java
  4. @Override
  5. public View getRealChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
  6. return null;
  7. }
  8. @Override
  9. public int getRealChildrenCount(int groupPosition) {
  10. return 0;
  11. }
  12. ```