10

I'm Using Recycler View as my listview and CardView as list item. I want to expand the Cardview when I click on any item of the list like it expands in inbox app by Google/Gmail. Please guide!

Raghavendra
  • 2,305
  • 25
  • 30
Zeeshan Ahmed
  • 1,179
  • 2
  • 13
  • 30
  • 1
    http://android-developers.blogspot.in/2014/10/implementing-material-design-in-your.html check Activity + Fragment Transitions – random Apr 09 '15 at 07:49
  • I Already check this But unable to implement it in my code. Please explain! – Zeeshan Ahmed Apr 09 '15 at 08:00
  • 3
    @random activity + fragment transitions only work with android 5 but inbox works with less than that. Point to be noted !! – neaGaze Apr 09 '15 at 08:17
  • 1
    Yes, I note this, and That's why following inbox. – Zeeshan Ahmed Apr 09 '15 at 08:41
  • @ZeeshanAhmed you might be interested in watching this devbytes https://www.youtube.com/watch?v=CPxkoe2MraA and this post http://stackoverflow.com/questions/27344357/android-5-activity-transition-on-lower-api – random Apr 09 '15 at 09:11
  • @ZeeshanAhmed : Any best sample code? – Jai Dec 22 '15 at 09:17

1 Answers1

3

Trick: You can change one of your item's height (inside your CardView) in your adapter. For example i have TextView in my CardView, when CardView item is clicked, i change height of TextView to 300:

public class courseListAdapter extends ListAdapter<courseListAdapter.ViewHolder> {
....
public class ViewHolder extends RecyclerView.ViewHolder implements
                View.OnClickListener,View.OnLongClickListener{
    TextView courseCRN;      
    ....
    public ViewHolder(View itemView, ClickListener listener)  {
        super(itemView);
        courseCRN = (TextView) itemView.findViewById(R.id.course_crn);

    }
    @Override
    public void onClick(View v) {   

                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, 300, 1f);
                    courseCRN.setLayoutParams(lp);


     }
}

Initial:

enter image description here

Later:

enter image description here

Jemshit
  • 9,501
  • 5
  • 69
  • 106
  • But does this replace the toolbar with the new toolbar like view with sleak transitions? – neaGaze Apr 09 '15 at 08:18
  • @neaGaze No, this trick just changes `CardView` `height` when it is clicked. – Jemshit Apr 09 '15 at 08:22
  • 1
    i think you wanted something else :D – Jemshit Apr 09 '15 at 08:24
  • @neaGaze is right, it will just change the cardview height. The same thing can also be achieved using setting some item's visibility. – Zeeshan Ahmed Apr 09 '15 at 08:43
  • @ZeeshanAhmed i think you can listen to recyclerview scroll state and change height again. Of yourse you can add transition to change height slowly. Check for scrollListener:http://stackoverflow.com/a/25481140/3736955 – Jemshit Apr 09 '15 at 08:48
  • there is not scroll inside cardview, it is just list item. Recyclerview has scrolling. – Jemshit Apr 09 '15 at 08:53