• Android通过RecyclerView实现手风琴效果


    Android通过RecyclerView实现手风琴效果

    • Android中RecyclerView动态列表中点击每一项Item展开列表详细内容
    • 关于RecyclerView使用二,通过RecyclerView 实现简单的手风琴折叠效果的一个记录。
    • 对于ExpandableListView又称可扩展的ListView,即每一个一级布局下都可以展开对应的二级布局。每一级布局都需要单独一个布局文件。
    • 对于简单的手风琴效果展示的列表内容,喜欢用RecyclerView实现,这样可以偷懒,少写布局文件。
    • 只是想用RecyclerView实现ExpandableListView的效果,提供一种实现方法和思路。
    • 简单实现手风琴效果如下:

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-od1gTPZk-1667052911532)(https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6728d7807b3b41d48b318810f9273fe0~tplv-k3u1fbpfcp-watermark.image?)]

    • RecyclerView页面布局:
            
            
      
                
      
            
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
    • RecyclerView列表的每一项布局文件
      
      
          
              
              
                  
                  
                  
                      
                      
                  
              
          
      
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
      • 32
      • 33
      • 34
      • 35
      • 36
      • 37
      • 38
      • 39
      • 40
      • 41
      • 42
      • 43
      • 44
      • 45
      • 46
      • 47
      • 48
      • 49
      • 50
      • 51
      • 52
      • 53
      • 54
      • 55
      • 56
      • 57
      • 58
      • 59
      • 60
      • 61
      • 62
      • 63
      • 64
      • 65
      • 66
      • 67
      • 68
      • 69
      • 70
      • 71
      • 72
      • 73
      • 74
      • 75
      • 76
      • 77
      • 78
      • 79
      • 80
      • 81
      • 82
      • 83
      • 84
      • 85
      • 86
      • 87
      • 88
      • 89
      • 90
      • 91
      • 92
      • 93
      • 94
      • 95
    • 设置适配器 ,实现点击折叠展示(其实是通过控制隐藏和显示布局实现手风琴折叠效果)
        //数据源 实体类
        public class MsgBean {
           
          private  String person_time;
          private  String person;
          private  String content;
          private  String contentMore;
          //构造函数 ,getter 、setter 方法省略不展示、
        }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
        import android.content.Context;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.LinearLayout;
        import android.widget.RelativeLayout;
        import android.widget.TextView;
      
        import androidx.cardview.widget.CardView;
        import androidx.recyclerview.widget.Rec
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
  • 相关阅读:
    Quartz如何实现判断某个任务是否正在运行--SpringCloud工作笔记181
    机器学习基础算法--回归类型和评价分析
    Redis数据类型-Set-基本使用
    渗透学习-CTF篇-web-ctfhub
    简单概括下get请求和post请求的区别
    C++之二叉搜索树详解
    安装使用electron
    Python-基础学习-第二轮
    大数据ClickHouse(十):MergeTree系列表引擎之SummingMergeTree
    [C# 中的序列化与反序列化](.NET 源码学习)
  • 原文地址:https://blog.csdn.net/weixin_44519188/article/details/127593135