{"id":13639048,"url":"https://github.com/diegodobelo/AndroidExpandingViewLibrary","last_synced_at":"2025-04-19T21:35:28.752Z","repository":{"id":201248852,"uuid":"58486585","full_name":"diegodobelo/AndroidExpandingViewLibrary","owner":"diegodobelo","description":"This is a library to help creating expanding views with animation in Android","archived":false,"fork":false,"pushed_at":"2018-08-24T11:21:06.000Z","size":992,"stargazers_count":946,"open_issues_count":18,"forks_count":122,"subscribers_count":37,"default_branch":"master","last_synced_at":"2024-08-03T01:13:46.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diegodobelo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-05-10T19:04:35.000Z","updated_at":"2024-07-18T14:16:46.000Z","dependencies_parsed_at":"2023-10-20T20:00:32.013Z","dependency_job_id":null,"html_url":"https://github.com/diegodobelo/AndroidExpandingViewLibrary","commit_stats":null,"previous_names":["diegodobelo/androidexpandingviewlibrary"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegodobelo%2FAndroidExpandingViewLibrary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegodobelo%2FAndroidExpandingViewLibrary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegodobelo%2FAndroidExpandingViewLibrary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegodobelo%2FAndroidExpandingViewLibrary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diegodobelo","download_url":"https://codeload.github.com/diegodobelo/AndroidExpandingViewLibrary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223810251,"owners_count":17206722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:00:57.058Z","updated_at":"2024-11-09T09:30:32.738Z","avatar_url":"https://github.com/diegodobelo.png","language":"Java","readme":"[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AndroidExpandingViewLibrary-green.svg?style=true)](https://android-arsenal.com/details/1/3667)\n## About the Library\n\n### inspiration\nThis library is strongly inspired in this concept from [Hila Peleg in dribble](https://dribbble.com/shots/2340386-Shopping-List).\nSee it below\n\n![Android Arsenal](https://raw.githubusercontent.com/tamzi/AndroidExpandingViewLibrary/master/art/shoping_list.gif)\n\n\n### Working example\nFor more details on how to use this library please refer to the example in this repository. You can see a video of the example working here: \n\n[![a video of the example working here](https://img.youtube.com/vi/moWaruuaEP0/0.jpg)](https://www.youtube.com/watch?v=moWaruuaEP0)\n\n\n\n## Adding the Library to gradle file\n```gradle\ndependencies {\n    compile 'com.diegodobelo.expandingview:expanding-view:0.9.4'\n}\n```\n\n## Using the Library\n### Layouts\nFirst of all include the ExpandingList in your Activity (or Fragment) layout. This will be the list of items (ExpandItem):\n\n```xml\n\u003ccom.diegodobelo.expandingview.ExpandingList\n        android:id=\"@+id/expanding_list_main\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"/\u003e\n```\n\nNow create a new layout (xml) file to represent the item (such as `res/layout/expanding_item.xml`). This will be the Item (header) that can be expanded to show sub items:\n\n```xml\n\u003cRelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"94dp\"\u003e\n    \u003cTextView\n        android:id=\"@+id/title\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_centerVertical=\"true\"\n        android:gravity=\"center_vertical|left\"\n        android:textSize=\"22sp\"/\u003e\n\u003c/RelativeLayout\u003e\n```\n\nCreate another layout file to represent the sub items (such as `/res/expanding_sub_item.xml`). This will be the sub items that will be shown when the Item is expanded:\n\n```xml\n\u003cRelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"48dp\"\u003e\n    \u003cTextView\n        android:id=\"@+id/sub_title\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:layout_centerVertical=\"true\"\n        android:layout_marginLeft=\"8dp\"\n        android:textSize=\"18sp\"\n        android:gravity=\"center_vertical|left\"/\u003e\n\u003c/RelativeLayout\u003e\n```\n\nNow create a layout file (such as `/res/expanding_layout.xml`) to represent the whole item, including both item layout and sub item layout. We will explain each custom attribute later:\n\n```xml\n\u003ccom.diegodobelo.expandingview.ExpandingItem\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    app:item_layout=\"@layout/expanding_item\"\n    app:sub_item_layout=\"@layout/expanding_sub_item\"\n    app:indicator_size=\"42dp\"\n    app:indicator_margin_left=\"16dp\"\n    app:indicator_margin_right=\"16dp\"\n    app:show_indicator=\"true\"\n    app:show_animation=\"true\"\n    app:start_collapsed=\"true\"\n    app:animation_duration=\"250\"/\u003e\n```\n\nNote that we included `expanding_item` and `expanding_sub_item` layouts created before.\n\n### Java code\n\nNow that you have all the required layouts you are able to use them in Java code. Let's start inflating the ExpandingList:\n\n```java\nExpandingList expandingList = (ExpandingList) findViewById(R.id.expanding_list_main);\n```\n\nCreate a new ExpandingItem in the ExpandingList. This method receives the `expanding_layout` created before. Yes! We can have different layouts for different items in the same list. The items will be created based on `expanding_item` layout and the sub items will be created based on `expanding_sub_item` layout:\n\n```java\nExpandingItem item = expandingList.createNewItem(R.layout.expanding_layout);\n\n/*ExpandingItem extends from View, so you can call\nfindViewById to get any View inside the layout*/\n(TextView) item.findViewById(R.id.title)).setText(\"It Works!!\");\n```\n\nLet's create the sub items. There is a method to create items in batch:\n\n```java\n//This will create 5 items\nitem.createSubItems(5);\n\n//get a sub item View\nView subItemZero = item.getSubItemView(0);\n((TextView) subItemZero.findViewById(R.id.sub_title)).setText(\"Cool\");\n\nView subItemOne = item.getSubItemView(1);\n((TextView) subItemOne.findViewById(R.id.sub_title)).setText(\"Awesome\");\n\n...\n\n```\n\nFor each item you can set the indicator color and the indicator icon:\n\n```java\nitem.setIndicatorColorRes(R.color.blue);\nitem.setIndicatorIconRes(R.drawable.ic_icon);\n\n```\n### ExpandingItem layout attributes\n\nAttribute Name         | Type         | Default Value | Meaning                                                             | Mandatory\n---------------------- | ------------ | ------------- | --------------------------------------------------------------------| --------\nitem_layout            | reference    |               | The layout for the Item (header).                                   | Yes\nsub_item_layout        | reference    |               | The layout for the sub items.                                       | Yes\nseparator_layout       | reference    |               | A layout to separate items.                                         | No\nindicator_size         | dimension    |       0dp     | The indicator size in dp.                                           | No\nindicator_margin_left  | dimension    |       0dp     | The margin between the indicator and its left.                      | No\nindicator_margin_right | dimension    |       0dp     | The margin between the indicator and its right.                     | No\nshow_indicator         | boolean      |       true    | true if you want to show the indicator. false otherwise.            | No\nshow_animation         | boolean      |       true    | true if you want to show animations. false otherwise.               | No\nstart_collapsed        | boolean      |       true    | true if you want the sub views to start collapsed. false otherwise. | No\nanimation_duration     | integer      |       300ms   | The animations duration in milliseconds.                            | No\n\n## ExpandingList public methods\n\n##### `public void createNewItem(int layoutId)`\n\nMethod to create and add a new item.\n\n * **Parameters:** `layoutId` — The item Layout\n\n##### `public void removeItem(ExpandingItem item)`\n\n Method to remove an item.\n\n * **Parameters:** `item` — The item to be removed, of type {@link ExpandingItem}\n\n##### `public void removeAllViews()`\n\nMethod to remove all items.\n\n##### `ExpandingItem getItemByIndex(int index)`\n\nMethod to get an Item from the ExpandingList by its index.\n\n* **Parameters:** `index` — The index of the item.\n* **Returns:** An {@link ExpandingItem} in the list.\n\n##### `public int getItemsCount()`\n\n Return how many items exists in the list.\n\n* **Returns:** Items count.\n\n## ExpandingItem public methods\n\n##### `public void setStateChangedListener(OnItemStateChanged listener)`\n\nSet a listener to listen item stage changed.\n\n * **Parameters:** `listener` — The listener of type {@link OnItemStateChanged}\n\n##### `public boolean isExpanded()`\n\nTells if the item is expanded.\n\n * **Returns:** true if expanded. false otherwise.\n\n##### `public int getSubItemsCount()`\n\nReturns the count of sub items.\n\n * **Returns:** The count of sub items.\n\n##### `public void collapse()`\n\nCollapses the sub items.\n\n##### `public void toggleExpanded()`\n\nExpand or collapse the sub items.\n\n##### `public void setIndicatorColorRes(int colorRes)`\n\nSet the indicator color by resource.\n\n * **Parameters:** `colorRes` — The color resource.\n\n##### `public void setIndicatorColor(int color)`\n\nSet the indicator color by color value.\n\n * **Parameters:** `color` — The color value.\n\n##### `public void setIndicatorIconRes(int iconRes)`\n\nSet the indicator icon by resource.\n\n * **Parameters:** `iconRes` — The icon resource.\n\n##### `public void setIndicatorIcon(Drawable icon)`\n\nSet the indicator icon.\n\n * **Parameters:** `icon` — Drawable of the indicator icon.\n\n##### `@Nullable public View createSubItem()`\n\nCreates a sub item based on sub_item_layout Layout, set as ExpandingItem layout attribute.\n\n * **Returns:** The inflated sub item view.\n\n##### `@Nullable public View createSubItem(int position)`\n\nCreates a sub item based on sub_item_layout Layout, set as ExpandingItem layout attribute. If position is -1, the item will be added in the end of the list.\n\n * **Parameters:** `position` — The position to add the new Item. Position should not be greater than the list size.\n * **Returns:** The inflated sub item view.\n\n##### `public void createSubItems(int count)`\n\nCreates as many sub items as requested in {@param count}.\n\n * **Parameters:** `count` — The quantity of sub items.\n\n##### `public View getSubItemView(int position)`\n\nGet a sub item at the given position.\n\n * **Parameters:** `position` — The sub item position. Should be \u003e 0.\n * **Returns:** The sub item inflated view at the given position.\n\n##### `public void removeSubItemAt(int position)`\n\nRemove sub item at the given position.\n\n * **Parameters:** `position` — The position of the item to be removed.\n\n##### `public void removeSubItemFromList(View view)`\n\nRemove the given view representing the sub item. Should be an existing sub item.\n\n * **Parameters:** `view` — The sub item to be removed.\n\n##### `public void removeSubItem(View view)`\n\nRemove the given view representing the sub item, with animation. Should be an existing sub item.\n\n * **Parameters:** `view` — The sub item to be removed.\n\n##### `public void removeAllSubItems()`\n\nRemove all sub items.\n\n## License\n```\n Copyright (c) 2016, Diego Bezerra \u003cdiego.bezerra@gmail.com\u003e\n Permission to use, copy, modify, and/or distribute this software for any purpose\n with or without fee is hereby granted, provided that the above copyright notice\n and this permission notice appear in all copies.\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,\n OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,\n DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\n ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n```\n","funding_links":[],"categories":["ListView","etc","Java"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegodobelo%2FAndroidExpandingViewLibrary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegodobelo%2FAndroidExpandingViewLibrary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegodobelo%2FAndroidExpandingViewLibrary/lists"}