The preparatory work

The XML layout file implements two RelativeLayout and two TextViews each to display the content

The key code

Adapter classes:

List list data encapsulation, recyclerView data display.

/ / set can shrink the public void setExpandCollapseDataList List (List) {

mlist = list;

notifyDataSetChanged(); }

Click on the response function

@Override

public void onClick(View view) {

if(mViewholder ! =null){

mViewholder.rlChild.setVisibility(View.GONE);

notifyItemChanged(expandPosition);

}

Fragments class:

Private list <String> mList = new ArrayList<>();Copy the code

adapter myadapter = new adapter(getActivity()); . / / bind adapter rcvExpandCollapse setAdapter (myadapter);

myadapter.setExpandCollapseDataList(mlist);

Implementation effect

Source code address: github.com/learnway299…

See blog address: blog.csdn.net/weixin_4472…