A custom view that is similar to the behavior of the iOS notification group

requirement

  • A project configured with AndroidX
  • SDK 16 and higher

To install

Download via Gradle::

Add this to the Project build.gradle File:

allprojects { repositories { ... maven { url "https://jitpack.io" } }
}

And then add the dependency to the module build.gradle File:

dependencies { implementation 'com.github.fabiosassu:StackExpandableView:latest_version'
}

In which the latest_version is the value of Download Badge.

use

Easy handling

All you have to do is define a StackExpandableView Element in your layout:

 <it.fabiosassu.stackexpandableview.StackExpandableView android:id="@+id/horizontalStack" android:layout_width="wrap_content" android:layout_height="wrap_content" app:orientation="horizontal" app:animationDuration="1000" app:shownElements="5" app:parallaxOffset="8dp"/>

You can customize some aspects of this view:

  • the orientation Parameter is used to indicate the direction of expansion. It can be either vertical or horizontal. The default is vertical.
  • the animationDuration The parameter defines the duration of the animation in milliseconds. The default is 300 milliseconds.
  • the shownElements The parameter defines how many elements are to be displayed. There are 3 items by default.
  • the parallaxOffset The parameter is used to define the distance between the underlying objects in dp. The default is 8dp.

At runtime, you can set / add / remove a list of views using the associated methods

// this is used to set the list of Views
binding.horizontalStack.setWidgets(listOf<LinearLayout>())// this is used to add a View to the existing one
binding.verticalStack.addWidget(LinearLayout(context))// this is used to remove a View from the stack
binding.verticalStack.removeWidget(LinearLayout(context))

It is important that any views that are added to the StackExpandableView have set an ID (for example with ViewCompat.generateViewId()) because it is used to organize the views internally and also look for the view when removeWidget() is called.

LEAVE A REPLY

Please enter your comment!
Please enter your name here