学习目的
学习ListView控件,达成页面大量数据的滑动需求
学习过程
简单使用ListView的相关操作,重点通过实战来理解整个的开发过程
技术
一、简单页面滚动实现
先看看效果:
这里做了一个点按跳转,外加变色的功能

1.适配器设置
展示页面中的内容:

2.响应事件
响应用户的点按操作:

3.数据导入
添加数据入页面

4.layout文件
step1:
打开res文件夹,定位到layout文件夹

step2:
在layout文件夹中创建一个新的资源文件


二、实战:联系人列表
老样子,先看看效果:

1.结构化思路

2.具体实现
1)类似的,创建ListView,展示页面中内容

2)显示的内容是一个头像和名称,将其作为一个模型整体处理




3)创建(导入)模型的数据
这里是自己虚构的数据,仅供打样示意^_^

4)一些微小的设置
这里是将头像显示由控件默认的矩形裁剪为圆形显示。
另:还可以做其他的一些元素设置

感悟
这次的实战项目,让我感受到了一种良好的工程方式,即高内聚,低耦合的工程搭建。为了使项目逻辑结构更加清晰,将一些功能抽离出来,独自成块,增强了代码的可移植性和鲁棒性。不仅如此,这种模式还使得代码的灵活性提高,能够应用于更多的场景,以适应更多元的需求。
虽然刚接触这种模式会有不适应(毕竟是牺牲了部分代码可读性的),但它的价值却是实打实的。多尝试,多运用,自然也能游刃有余。
网友评论