Android实现时光轴布局效果源代码下载
程序员文章站
2022-03-01 12:51:56
...
最近项目里面需要使用到时光轴的效果、查了很多资料、最后利用ExpandableListView通过对布局的控制来实现时光轴效果、代码好用易懂、集成到自己的项目里面非常方便、希望对大家有用、下面是效果图
初始化可拓展列表
private void initExpandListView() { statusAdapter = new StatusExpandAdapter(context, getListData()); expandlistView.setAdapter(statusAdapter); expandlistView.setGroupIndicator(null); // 去掉默认带的箭头 expandlistView.setSelection(0);// 设置默认选中项 AseoZdpAseo.initFinalTimer(this, AseoZdpAseo.BOTH_TYPE); // 遍历所有group,将所有项设置成默认展开 int groupCount = expandlistView.getCount(); for (int i = 0; i < groupCount; i ) { expandlistView.expandGroup(i); } expandlistView.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { // TODO Auto-generated method stub return true; } }); }
数据初始化
private List<GroupStatusEntity> getListData() { List<GroupStatusEntity> groupList; String[] strArray = new String[] { "10月22日", "10月23日", "10月24日" }; String[][] childTimeArray = new String[][] { { "俯卧撑十次", "仰卧起坐二十次", "大喊我爱紫豪二十次", "每日赞紫豪一次" }, { "亲,快快滴点赞哦~","仰卧起坐二十次","睡觉20小时","打坐4小时" }, { "没有赞的,赶紧去赞哦~","亲,快快滴点赞哦~","仰卧起坐二十次","跑步20分钟","运动2小时" } }; groupList = new ArrayList<GroupStatusEntity>(); for (int i = 0; i < strArray.length; i ) { GroupStatusEntity groupStatusEntity = new GroupStatusEntity(); groupStatusEntity.setGroupName(strArray[i]); List<ChildStatusEntity> childList = new ArrayList<ChildStatusEntity>(); for (int j = 0; j < childTimeArray[i].length; j ) { ChildStatusEntity childStatusEntity = new ChildStatusEntity(); childStatusEntity.setCompleteTime(childTimeArray[i][j]); childStatusEntity.setIsfinished(true); childList.add(childStatusEntity); } groupStatusEntity.setChildList(childList); groupList.add(groupStatusEntity); } return groupList; }
StatusExpandAdapter代码已经封装好了、如果跟自己的项目不相符的可以改造一下、代码里面都有注释的、非常好理解的
最后给贴上Demo的源代码、希望对大家有用、有兴趣的哥们可以下载看看
源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1mg7yME0 密码: mr8x