一、开发背景

实现类似“膜拜”app里面的行车日志的功能

二、看实现后的效果

三、分析:

刚刚看到这个需求的时候,是不是也感觉跟我一样,不知道怎么入手。我们把分析图先画出来。如上图,实现的方法是listView里面嵌套我们需要的一个布局。这样我们就能够搞定高度随着我们内容的不同而自适应高度了。

四、代码部分

1. 先写两个布局

(1)对应Activity的布局activity_log_list.xml;

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/activity_log_list"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@mipmap/me_bg"tools:context="cn.bql.vehiclemounted.vehiclemounteds.activity.LogListActivity">//这个是title,可不管<includeandroid:id="@+id/include"layout="@layout/public_title" /><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/include"><ListViewandroid:id="@+id/listViewTime"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="@+id/textView5"android:divider="@null"android:padding="5dp" /><ProgressBarandroid:id="@+id/probarLog"android:layout_width="30dp"android:layout_height="30dp"android:layout_centerHorizontal="true"android:layout_marginTop="350dp" /><TextViewandroid:id="@+id/textView5"android:layout_width="match_parent"android:layout_height="40dp"android:layout_alignParentBottom="true" /></RelativeLayout>//下边的按钮<LinearLayoutandroid:id="@+id/linearLayout"android:layout_width="match_parent"android:layout_height="40dp"android:layout_alignParentBottom="true"android:background="#000"android:gravity="center"android:visibility="gone"><TextViewandroid:id="@+id/addLog"android:layout_width="80dp"android:layout_height="35dp"android:layout_gravity="center"android:background="@drawable/selector_btn_lvse"android:gravity="center"android:text="添加日志"android:textSize="16sp" /></LinearLayout>
</RelativeLayout>

2. 需要填充在listView 适配器adapter的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"android:weightSum="5">//日期<TextViewandroid:id="@+id/tv_timelog"android:layout_width="45dp"android:layout_height="40dp"android:layout_marginTop="15dp"android:gravity="center"android:textColor="#686A6F" /><RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="match_parent">//竖的线条<Viewandroid:id="@+id/shiguangzhou1"android:layout_width="1dp"android:layout_height="15dp"android:layout_marginLeft="20dp"android:background="#2E96BB" />//光轴的圆形图标<ImageViewandroid:layout_below="@id/shiguangzhou1"android:id="@+id/imageView1"android:layout_width="35dp"android:layout_height="35dp"android:background="@mipmap/ic_baoyang_icon" />        //竖的线条<View android:id="@+id/shiguangzhou" android:layout_below="@id/imageView1" android:layout_width="1dp" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:background="#2E96BB" /></RelativeLayout><LinearLayout android:layout_width="match_parent"                       android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="5dp" android:layout_marginTop="15dp" android:background="@drawable/log_bg" android:orientation="vertical" android:padding="5dp">//title数据<TextView android:textColor="@color/et_clolr" android:id="@+id/tv_title_project" android:layout_width="match_parent" android:layout_height="match_parent" android:text="养护了很多项" android:textSize="14sp" />//数据内容<TextView android:layout_marginTop="5dp" android:id="@+id/tv_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:text="@string/app_name" android:textSize="13sp" android:textColor="#686A6F" /></LinearLayout>
</LinearLayout>   

1.LogListActivity方法


/**
* 日志列表显示
*/
public class LogListActivity extends BaseActivity {/*** 自定义适配器*/public class MyAdapter extends BaseAdapter {private LayoutInflater layoutInflater;public final class ViewHolder { //自定义控件集合public TextView tv_timelog;public ImageView imageView;public TextView tv_content;public TextView tv_title;}public MyAdapter(Context context) {this.layoutInflater = LayoutInflater.from(context);}@Overridepublic int getCount() {return carLogBeaninfo == null ? 0 : carLogBeaninfo.getCount();}@Overridepublic Object getItem(int position) {return carLogBeaninfo.getDay_data().get(position);}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int position, View view, ViewGroup parent) {//自定义视图ViewHolder holder = null;if (view == null) {holder = new ViewHolder();//获取list_item布局文件的视图view = layoutInflater.inflate(R.layout.group_status, null);//获取控件对象holder.tv_timelog = (TextView) view.findViewById(R.id.tv_timelog);holder.imageView = (ImageView) view.findViewById(R.id.imageView1);holder.tv_content = (TextView) view.findViewById(R.id.tv_content);holder.tv_title = (TextView) view.findViewById(R.id.tv_title_project);view.setTag(holder);} else {holder = (ViewHolder) view.getTag();}String time = carLogBeaninfo.getDay_data().get(position).getCare_date();String[] sourceStrArray = time.split("-");String times = sourceStrArray[0] + "\n" + sourceStrArray[1] + "." +         sourceStrArray[2];holder.tv_timelog.setText(times);Glide.with(mContext).load(R.mipmap.ic_baoyang_icon).into(holder.imageView);String s = "";for (int i = 0; i < carLogBeaninfo.getDay_data().get(position).getCount(); i++) {s = s + (i+1) + "."+carLogBeaninfo.getDay_data().get(position).getCare_data().get(i).getContent() + ";" + "\n";}holder.tv_content.setText(s.trim() + "");String title = "您做了 " + carLogBeaninfo.getDay_data().get(position).getCare_data().get(0).getContent() +" 等" + carLogBeaninfo.getDay_data().get(position).getCount() + "个保养项";holder.tv_title.setText(title);return view;}}
}

这里面主要看适配器即可,数据请求需要根据自己的项目需求自己去获取即可。
总结:也就是说,时光轴的难点其实就是布局这一块,了解了只要基础不是太差,都能够完成。

《Android 时光轴实现》相关推荐

  1. ComeFuture英伽学院——2020年 全国大学生英语竞赛【C类初赛真题解析】(持续更新)

    视频:ComeFuture英伽学院--2019年 全国大学生英语竞赛[C类初赛真题解析]大小作文--详细解析 课件:[课件]2019年大学生英语竞赛C类初赛.pdf 视频:2020年全国大学生英语竞赛 ...

  2. ComeFuture英伽学院——2019年 全国大学生英语竞赛【C类初赛真题解析】大小作文——详细解析

    视频:ComeFuture英伽学院--2019年 全国大学生英语竞赛[C类初赛真题解析]大小作文--详细解析 课件:[课件]2019年大学生英语竞赛C类初赛.pdf 视频:2020年全国大学生英语竞赛 ...

  3. 信息学奥赛真题解析(玩具谜题)

    玩具谜题(2016年信息学奥赛提高组真题) 题目描述 小南有一套可爱的玩具小人, 它们各有不同的职业.有一天, 这些玩具小人把小南的眼镜藏了起来.小南发现玩具小人们围成了一个圈,它们有的面朝圈内,有的 ...

  4. 信息学奥赛之初赛 第1轮 讲解(01-08课)

    信息学奥赛之初赛讲解 01 计算机概述 系统基本结构 信息学奥赛之初赛讲解 01 计算机概述 系统基本结构_哔哩哔哩_bilibili 信息学奥赛之初赛讲解 02 软件系统 计算机语言 进制转换 信息 ...

  5. 信息学奥赛一本通习题答案(五)

    最近在给小学生做C++的入门培训,用的教程是信息学奥赛一本通,刷题网址 http://ybt.ssoier.cn:8088/index.php 现将部分习题的答案放在博客上,希望能给其他有需要的人带来 ...

  6. 信息学奥赛一本通习题答案(三)

    最近在给小学生做C++的入门培训,用的教程是信息学奥赛一本通,刷题网址 http://ybt.ssoier.cn:8088/index.php 现将部分习题的答案放在博客上,希望能给其他有需要的人带来 ...

  7. 信息学奥赛一本通 提高篇 第六部分 数学基础 相关的真题

    第1章   快速幂 1875:[13NOIP提高组]转圈游戏 信息学奥赛一本通(C++版)在线评测系统 第2 章  素数 第 3 章  约数 第 4 章  同余问题 第 5 章  矩阵乘法 第 6 章 ...

  8. 信息学奥赛一本通题目代码(非题库)

    为了完善自己学c++,很多人都去读相关文献,就比如<信息学奥赛一本通>,可又对题目无从下手,从今天开始,我将把书上的题目一 一的解析下来,可以做参考,如果有错,可以告诉我,将在下次解析里重 ...

  9. 信息学奥赛一本通(C++版) 刷题 记录

    总目录详见:https://blog.csdn.net/mrcrack/article/details/86501716 信息学奥赛一本通(C++版) 刷题 记录 http://ybt.ssoier. ...

  10. 最近公共祖先三种算法详解 + 模板题 建议新手收藏 例题: 信息学奥赛一本通 祖孙询问 距离

    首先什么是最近公共祖先?? 如图:红色节点的祖先为红色的1, 2, 3. 绿色节点的祖先为绿色的1, 2, 3, 4. 他们的最近公共祖先即他们最先相交的地方,如在上图中黄色的点就是他们的最近公共祖先 ...

最新文章

  1. Java延迟加载建议
  2. transformers理论解释
  3. [连载]JavaScript讲义(05)--- 数据处理
  4. robot:linux下安装robot环境
  5. Disqus API 用法 How to get your Disqus API keys
  6. 端到端加密优缺点_基于Filecoin的去中心化文件保存和加密分享平台
  7. GitHub项目:自然语言处理领域的相关干货整理
  8. 随想录(qemu的学习)
  9. mysql临时表多线程时能用吗_学会使用临时表优化,切记不要乱用临时表(记录一)...
  10. 华硕afudos刷bios_ASUS主板刷BIOS详细图解方法 包含windows和DOS两种环境
  11. 电压型传感器和电流型传感器的区别
  12. leetcode69
  13. 链表上手代码---表头插入
  14. 安卓和ios的ui设计区别_简析Android系统与ios系统界面设计区别
  15. macOS 安卓模拟器 Nox夜神模拟器 共享目录
  16. 阿里云ECS之下载与安装SSH(二)
  17. HTML5七夕情人节表白网页制作【3D雪花展开相册】HTML+CSS+JavaScript 程序员表白网页 简单的3D相册制作
  18. 赢在项目工具的落地-讲师团俊平老师主讲
  19. 苹果个人账号转公司账号
  20. 计算机网络的社会环境分析_计算机网络的功能和应用

热门文章

  1. 兵法:掌上千秋史 胸中百万兵
  2. 2019最新开发优质外贸客户方法渠道分享
  3. 感谢万商网《万商访谈》栏目对我的专访报导
  4. monkey煲机停止运行分析总结
  5. 在线快速制作老照片效果-幕末古写真
  6. Linux 3.进程间通信(shmget shmat shmdt shmctl 共享内存、signal signaction sigqueue 信号、semget semctl semop 信号量)
  7. 目标检测YOLO实战应用案例100讲-面向小样本的目标检测技术研究与应用
  8. 教你使用Anti ARP Sniffer查找ARP攻击者
  9. 大白话告诉你什么是Raid1
  10. flink中维表Join几种常见方式总结