Coder Social home page Coder Social logo

expandablecardview's Introduction

Before you try to use this library

This library is forked and modified for the app Cometin I tried making the library as functional for others but there might be some elements you don't like.

ExpandableCardView

Example Gif

An Android library that lets you create in a simple, fast and hassle-free way a CardView in which you can insert your custom layout and just expand and collapse without even writing a single Java/Kotlin line of code.

This component follows the Material Design Guidelines.

Demo

Get it on the Google Play Store.

Setup

First of all, include the dependency in your app build.gradle:

Stable

implementation 'com.github.Stjinchan:ExpandableCardView:1.2.2'

Or get the aar in the Releases section.

Declaring the view

After you have the Library correctly setup, just declare the ExpandableCardView in your xml:

<host.stjin.expandablecardview.ExpandableCardView
    android:id="@+id/profile"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:title="Passengers"
    app:icon="@drawable/ic_person"
    app:inner_view="@layout/mycustomview"
    app:expandOnClick="true"
    app:animationDuration="300"
    app:cardStrokeWidth="2dp"
    app:startExpanded="false"/>

The only required attributes are inner_view and title. The other attributes are optional.

You can specify a custom title and icon on the header on the card by setting the attribute app:title and app:icon respectively.

After you created the base xml, just create your custom layout and place it inside your layout folder.

Now just pass your newly created layout resource to the app:inner_view attribute. By setting the attribute app:expandOnClick="true" the card will have a default behaviour (expand/collapse on click); By setting the animationDuration attribute you can set a custom animation time, and by setting the startExpanded attribute the card will be automatically expanded when inflated.

Done! Now your ExpandableCardView is ready to roll.

Usage

If you want some basic Expandable Card without any custom behaviour, setting the view in the XML is enough. Otherwise just declare your ExpandableCardView in your Activity/Fragment and you're ready to use its methods.

Styling

app:expandOnClick="true"
app:expandableCardRipple="true"
app:expandableCardRadius="6dp"
app:expandableCardStrokeWidth="2dp"
app:expandableCardElevation="4dp"
app:expandableCardStrokeColor="@color/colorAccent"
app:expandableCardArrowColor="@color/colorAccent"
app:expandableCardTitleColor="@color/colorAccent"
app:expandableCardColor ="@color/colorAccent"
app:expandableCardTitleBold="true"
app:expandableCardTitleSize="14sp"
app:animationDuration="900"
app:startExpanded="true"
app:showSwitch="true"

Java

ExpandableCardView card = findViewById(R.id.profile);

 //Do stuff here

Kotlin

val card : ExpandableCardView = findViewById(R.id.profile)

 //Do stuff here

You can use expand() and collapse() to respectively expand and collapse the card, and use isExpanded() to check if the card is expanded or not. You can change the title and icon of the card dynamically by using setTitle() and setIcon() methods.

You can also set an OnExpandedListener to the card:

Java

card.setOnExpandedListener(new OnExpandedListener() {
    @Override
    public void onExpandChanged(View v, boolean isExpanded) {
        Toast.makeText(applicationContext, isExpanded ? "Expanded!" : "Collapsed!", Toast.LENGTH_SHORT).show();
    }
});

card.setOnSwitchChangeListener(new OnSwitchChangeListene() {
    @Override
    public void OnSwitchChangeListener(View v, boolean isChecked) {
        Toast.makeText(applicationContext, isChecked ? "Checked!" : "Not checked!", Toast.LENGTH_SHORT).show();
    }
});

Kotlin

card.setOnExpandedListener { view, isExpanded ->
    Toast.makeText(applicationContext, if(isExpanded) "Expanded!" else "Collapsed!", Toast.LENGTH_SHORT).show()
 }

 card.setOnSwitchChangeListener { view, isChecked ->
    Toast.makeText(applicationContext, if(isChecked) "Checked!" else "Not checked!", Toast.LENGTH_SHORT).show()
 }

License

  Copyright (c) 2018 Alessandro Sperotti
 
  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.
 

Author

Forked project, Made By Alessandro Sperotti.

alessandrosperotti at gmail dot com

If you liked this library, why don't you offer me or Allesandro a coffee (or a beer? :D)

ETH (Alessandro): 0x70b6b9eaCDf6f76ECb92bE3fb81d72B3971BA1Bc

Paypal (Stjinchan (me)): Donate

expandablecardview's People

Contributors

alespero avatar rizaldirpamungkas avatar stjin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

expandablecardview's Issues

Creating ExpandableCardViews dynamically

Is there a way to dynamically create ExpandableCardViews? Something like:

ExpandableCardView ecv = new ExpandableCardView(this);
ecv.setInnerView(...);
ecv.setTitleTextColor(...); 
// etc

I've tinkered a bit with this but couldn't find a way to programmatically set attributes for it.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.