expanding-collection-android
:octocat: ExpandingCollection is a material design card peek/pop controller. Android UI Library made by @Ramotion
Top Related Projects
✒7000+ Material Design Icons from the Community
Quick Overview
The Ramotion/expanding-collection-android repository is an Android library that provides a unique and visually appealing way to display a collection of items. It features an expanding/collapsing animation that allows users to explore the collection in a dynamic and engaging manner.
Pros
- Unique and Visually Appealing: The expanding/collapsing animation adds a distinctive and eye-catching element to the user interface.
- Smooth Animations: The library provides smooth and fluid animations that enhance the overall user experience.
- Customizable: The library offers various customization options, allowing developers to tailor the appearance and behavior to fit their specific needs.
- Well-Documented: The project's documentation is comprehensive and provides clear instructions for integration and usage.
Cons
- Limited to Android: The library is specifically designed for the Android platform and may not be suitable for cross-platform development.
- Performance Considerations: Depending on the size and complexity of the collection, the expanding/collapsing animations may impact the overall performance of the application.
- Learning Curve: Developers new to the library may need to invest time in understanding the API and integrating it into their existing codebase.
- Potential Compatibility Issues: As with any third-party library, there may be compatibility issues with certain Android versions or device configurations.
Code Examples
Here are a few code examples demonstrating the usage of the Ramotion/expanding-collection-android library:
// Initializing the ExpandingCollection
val expandingCollection = ExpandingCollection(context)
expandingCollection.setItems(items)
expandingCollection.setOnItemClickListener { item ->
// Handle item click event
}
// Customizing the appearance of the ExpandingCollection
expandingCollection.setBackgroundColor(Color.WHITE)
expandingCollection.setItemTitleTextColor(Color.BLACK)
expandingCollection.setItemSubtitleTextColor(Color.GRAY)
// Handling the expanding/collapsing state
expandingCollection.setOnStateChangeListener { isExpanded ->
// Perform actions based on the expanded/collapsed state
}
// Creating a custom item for the ExpandingCollection
class CustomItem(
val title: String,
val subtitle: String,
val imageResource: Int
) : ExpandingItem {
override fun getTitle(): String = title
override fun getSubtitle(): String = subtitle
override fun getImageResource(): Int = imageResource
}
// Animating the ExpandingCollection
expandingCollection.expand()
expandingCollection.collapse()
// Handling item selection
expandingCollection.setOnItemClickListener { item ->
// Perform actions based on the selected item
}
Getting Started
To get started with the Ramotion/expanding-collection-android library, follow these steps:
- Add the library to your project's
build.gradle
file:
dependencies {
implementation 'com.ramotion.expandingcollection:expanding-collection:1.2.0'
}
- In your activity or fragment, create an instance of the
ExpandingCollection
and set the items to be displayed:
val expandingCollection = ExpandingCollection(this)
val items = listOf(
CustomItem("Item 1", "Subtitle 1", R.drawable.image1),
CustomItem("Item 2", "Subtitle 2", R.drawable.image2),
// Add more items as needed
)
expandingCollection.setItems(items)
- Customize the appearance and behavior of the
ExpandingCollection
as needed:
expandingCollection.setBackgroundColor(Color.WHITE)
expandingCollection.setItemTitleTextColor(Color.BLACK)
expandingCollection.setItemSubtitleTextColor(Color.GRAY)
expandingCollection.setOnItemClickListener { item ->
// Handle item click event
}
- Add the
ExpandingCollection
to your layout:
<com.ramotion.expandingcollection.ExpandingCollection
android:id="@+id/expanding_collection"
android:layout_width="match_parent"
Competitor Comparisons
✒7000+ Material Design Icons from the Community
Pros of MaterialDesign
- Extensive collection of Material Design icons, covering a wide range of categories and use cases.
- Active community with regular updates and contributions, ensuring the icon set stays current.
- Detailed documentation and guidelines for using the icons in various design and development contexts.
Cons of MaterialDesign
- Primarily focused on providing icons, rather than a comprehensive UI component library like Expanding Collection Android.
- May require additional integration work to use the icons in an Android app, as it is not a direct Android library.
- Limited functionality beyond the icon set, compared to a dedicated UI component library.
Code Comparison
Expanding Collection Android:
ExpandingCollection expandingCollection = (ExpandingCollection) findViewById(R.id.expanding_collection);
expandingCollection.setMainView(mainView);
expandingCollection.setSecondaryViews(secondaryViews);
expandingCollection.setOnExpansionUpdateListener(new ExpansionUpdateListener() {
@Override
public void onExpansionUpdate(float expansionFraction, int state) {
// Handle expansion update
}
});
MaterialDesign:
<com.google.android.material.icon.MaterialIconView
android:id="@+id/icon"
android:layout_width="24dp"
android:layout_height="24dp"
app:materialIcon="android"
app:materialIconColor="@color/icon_color"
app:materialIconSize="24dp" />
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
EXPANDING COLLECTION
ExpandingCollection is a material design card peek/pop controller
We specialize in the designing and coding of custom UI for Mobile Apps and Websites.
Stay tuned for the latest updates:
Check this library on other platforms:
Requirements
â
- Android 4.0 IceCreamSandwich (API lvl 14) or greater
- Your favorite IDE
Installation
â maven repo:
Gradle:
'com.ramotion.expandingcollection:expanding-collection:0.9.2'
SBT:
libraryDependencies += "com.ramotion.expandingcollection" % "expanding-collection" % "0.9.2"
Maven:
<dependency>
<groupId>com.ramotion.expandingcollection</groupId>
<artifactId>expanding-collection</artifactId>
<version>0.9.2</version>
</dependency>
Basic usage
â
- Add a background switcher element
ECBackgroundSwitcherView
and a main pager elementECPagerView
to your layout.ECPagerView
should always havematch_parent
width andwrap_content
height. You can adjust the vertical position yourself using alignment/gravity or top margin.ECBackgroundSwitcherView
is the dynamic background switcher, so you probably want it to be as big as its parent.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.ramotion.expandingcollection.ECBackgroundSwitcherView
android:id="@+id/ec_bg_switcher_element"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.ramotion.expandingcollection.ECPagerView
android:id="@+id/ec_pager_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
- Tune
ECPagerView
: setup size of card in collapsed state and height of header in expanded state.
<com.ramotion.expandingcollection.ECPagerView xmlns:ec="http://schemas.android.com/apk/res-auto"
android:id="@+id/ec_pager_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
ec:cardHeaderHeightExpanded="150dp"
ec:cardHeight="200dp"
ec:cardWidth="250dp" />
- Expanded card contains two parts: a header part with a background (initially visible when card is collapsed) and a ListView element as content (visible only when card is expanded), so you need an xml layout for the list items.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_text"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@color/colorPrimary"
android:textAlignment="center" />
</FrameLayout>
- Also, you need to implement a custom list adapter for the list items by extending the parametrized
com.ramotion.expandingcollection.ECCardContentListItemAdapter.java
class, whereT
is type of datasource object for list items inside the card. In the example below,T
is just a string object. It's a pretty straightforward implementation with a common view holder pattern.
public class CardListItemAdapter extends ECCardContentListItemAdapter<String> {
public CardListItemAdapter(@NonNull Context context, @NonNull List<String> objects) {
super(context, R.layout.list_item, objects);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
ViewHolder viewHolder;
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
rowView = inflater.inflate(R.layout.list_item, null);
viewHolder = new ViewHolder();
viewHolder.itemText = (TextView) rowView.findViewById(R.id.list_item_text);
rowView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) rowView.getTag();
}
String item = getItem(position);
if (item != null) {
viewHolder.itemText.setText(item);
}
return rowView;
}
static class ViewHolder {
TextView itemText;
}
}
- Your data class must implement the
com.ramotion.expandingcollection.ECCardData.java
interface whereT
is type of datasource object for list items inside the card.
public class CardDataImpl implements ECCardData<String> {
private String cardTitle;
private Integer mainBackgroundResource;
private Integer headBackgroundResource;
private List<String> listItems;
@Override
public Integer getMainBackgroundResource() {
return mainBackgroundResource;
}
@Override
public Integer getHeadBackgroundResource() {
return headBackgroundResource;
}
@Override
public List<String> getListItems() {
return listItems;
}
}
- Almost done! The last thing we need to do is provide our dataset to a pager element through a pager adapter. It's just an implementation of the abstract class
com.ramotion.expandingcollection.ECPagerViewAdapter.java
with one abstract method, so it can be easily implemented inside your activity.
public class MainActivity extends Activity {
private ECPagerView ecPagerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get pager from layout
ecPagerView = (ECPagerView) findViewById(R.id.ec_pager_element);
// Generate example dataset
List<ECCardData> dataset = CardDataImpl.generateExampleData();
// Implement pager adapter and attach it to pager view
ecPagerView.setPagerViewAdapter(new ECPagerViewAdapter(getApplicationContext(), dataset) {
@Override
public void instantiateCard(LayoutInflater inflaterService, ViewGroup head, ListView list, ECCardData data) {
// Data object for current card
CardDataImpl cardData = (CardDataImpl) data;
// Set adapter and items to current card content list
list.setAdapter(new CardListItemAdapter(getApplicationContext(), cardData.getListItems()));
// Also some visual tuning can be done here
list.setBackgroundColor(Color.WHITE);
// Here we can create elements for head view or inflate layout from xml using inflater service
TextView cardTitle = new TextView(getApplicationContext());
cardTitle.setText(cardData.getCardTitle());
cardTitle.setTextSize(COMPLEX_UNIT_DIP, 20);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
head.addView(cardTitle, layoutParams);
// Card toggling by click on head element
head.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
ecPagerView.toggle();
}
});
}
});
// Add background switcher to pager view
ecPagerView.setBackgroundSwitcherView((ECBackgroundSwitcherView) findViewById(R.id.ec_bg_switcher_element));
}
// Card collapse on back pressed
@Override
public void onBackPressed() {
if (!ecPagerView.collapse())
super.onBackPressed();
}
}
You can find this and other, more complex, examples in this repository â
ð Check this library on other language:
ð License
Expanding Collection Android is released under the MIT license. See LICENSE for details.
This library is a part of a selection of our best UI open-source projects
If you use the open-source library in your project, please make sure to credit and backlink to www.ramotion.com
ð± Get the Showroom App for Android to give it a try
Try this UI component and more like this in our Android app. Contact us if interested.
Top Related Projects
✒7000+ Material Design Icons from the Community
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot