Skip to content
프로젝트

소개

확장 가능한 LinearLayout

디자인 및 미디어

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
-1
in 1 month
-4

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

ExpandableLayout

Android CI JitPack

Expandable LinearLayout

Setup

Dependency

settings.gradle

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

Module build.gradle

dependencies {
    implementation 'com.github.iammert:ExpandableLayout:2.0.0'
}

Requires minSdk 21.

Layout

<iammert.com.expandablelib.ExpandableLayout
    android:id="@+id/el"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:parentLayout="@layout/layout_parent"
    app:childLayout="@layout/layout_child"
    app:singleExpansion="false"
    app:animateExpansion="true"
    app:toggleOnParentClick="true"/>
Attribute Description
parentLayout Layout of a parent row (required)
childLayout Layout of a child row (required)
singleExpansion Collapse the other sections when one is expanded
animateExpansion Animate rows on expand/collapse
toggleOnParentClick Expand/collapse when the parent row is tapped, true by default

All of them have setters, e.g. setParentLayout() when the layout is created from code. Give the layout an id so the expanded sections are restored after rotation.

Set renderer

expandableLayout.setRenderer(new ExpandableLayout.Renderer<FruitCategory, Fruit>() {
    @Override
    public void renderParent(View view, FruitCategory model, boolean isExpanded, int parentPosition) {
        ((TextView) view.findViewById(R.id.tvParent)).setText(model.name);
        view.findViewById(R.id.arrow).setRotation(isExpanded ? 180 : 0);
    }

    @Override
    public void renderChild(View view, Fruit model, int parentPosition, int childPosition) {
        ((TextView) view.findViewById(R.id.tvChild)).setText(model.name);
    }
});

renderParent() is called again whenever the section expands or collapses.

Set listeners

expandableLayout.setExpandListener((ExpandCollapseListener.ExpandListener<FruitCategory>)
        (parentIndex, parent, view) -> { /* section expanded */ });

expandableLayout.setCollapseListener((ExpandCollapseListener.CollapseListener<FruitCategory>)
        (parentIndex, parent, view) -> { /* section collapsed */ });

expandableLayout.setOnChildClickListener((OnChildClickListener<FruitCategory, Fruit>)
        (parentIndex, parent, childIndex, child, view) -> { /* child clicked */ });

Add sections or children

FruitCategory fruits = new FruitCategory("Fruits");
Section<FruitCategory, Fruit> section =
        new Section<>(fruits, Arrays.asList(new Fruit("Apple"), new Fruit("Orange")), true);

expandableLayout.addSection(section);
expandableLayout.addSections(otherSections);
expandableLayout.addChild(fruits, new Fruit("Grape"));
expandableLayout.addChildren(fruits, Arrays.asList(new Fruit("Cherry"), new Fruit("Plum")));

Remove or update

expandableLayout.removeChild(fruits, grape);
expandableLayout.removeSection(0); // or removeSection(fruits)
expandableLayout.removeAllSections();

expandableLayout.notifyParentChanged(0);
expandableLayout.notifyChildChanged(0, 1);
expandableLayout.notifyDataSetChanged(); // after changing sections directly

Expand and collapse from code

expandableLayout.expand(0);          // or expand(fruits)
expandableLayout.collapse(fruits);
expandableLayout.toggle(1);
expandableLayout.expandAll();
expandableLayout.collapseAll();
boolean expanded = expandableLayout.isExpanded(0);

Filter parents and children

Filters stay active for sections and children added later and can be combined.

expandableLayout.filterParent(obj -> ((FruitCategory) obj).name.startsWith("F"));
expandableLayout.filterChildren(obj -> ((Fruit) obj).name.toLowerCase().contains(query));
expandableLayout.clearFilter();

Changelog

See CHANGELOG.md.

License

Copyright 2017 Mert Şimşek.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

관련 프로젝트 살펴보기

불러오는 중…