探索流式布局:百分比与移动Web开发实践

需积分: 5 0 下载量 120 浏览量 更新于2024-08-03 收藏 8KB MD 举报
"**流式布局与京东移动端首页设计**" 流式布局是现代Web设计中的重要概念,特别是在响应式设计中占据核心地位。它是一种非固定像素的布局方法,主要特点是元素宽度采用百分比单位,而非固定的像素值,从而允许页面元素随着屏幕尺寸的变化自动调整其大小和位置。这种布局方式的优势在于适应不同设备的屏幕大小,提供良好的用户体验。 ### 1.1 流式布局详解 - **百分比布局**:流式布局的核心是元素宽度设置为百分比,如`width:50%`,使得元素能够根据容器的宽度动态伸缩。 - **自由伸缩**:不受屏幕分辨率限制,内容会自动填充容器两侧,使布局在各种屏幕尺寸下保持灵活性。 - **移动Web开发常用**:随着移动设备的普及,流式布局成为构建适应性网站的首选,如响应式网页设计中不可或缺的一部分。 ### 1.2 案例演示 以下是一个简单的HTML结构,展示了流式布局的应用: ```html <head> <style> section { width: 100%; max-width: 980px; min-width: 320px; margin: 0 auto; /* 居中显示 */ } section div { float: left; width: 50%; height: 400px; background-color: alternating colors; /* 蓝色和天空蓝 */ } /* nth-child伪类用于区分两个div */ section div:nth-child(1) { background-color: blue; } section div:nth-child(2) { background-color: skyblue; } </style> </head> <body> <section> <div></div> <div></div> </section> </body> ``` 图片18展示的是这个例子的实际效果,两个宽度相等的div在父元素`section`中水平排列,可以根据屏幕宽度进行自适应。 ### 2. 京东移动端首页案例 京东移动端首页的布局采用了流式布局策略,以确保在不同设备上呈现一致且美观的界面。 #### 2.1 效果图 图片19展示了京东移动端首页设计的一个实例,可能包括灵活的导航栏、适应不同屏幕大小的商品列表和内容区域。 #### 2.2 响应式设计步骤 - **设置视口标签**:通过`<meta name="viewport">`标签,控制页面缩放和布局,保证在移动设备上的最佳体验。 - **CSS初始化样式**:引入第三方的`normalize.css`库,统一浏览器默认样式,以及自定义的`index.css`样式表,实现布局和样式的统一管理。 通过以上内容,我们可以看到流式布局在实际项目中的应用,无论是基本的两列布局还是像京东这样的复杂响应式设计,都离不开百分比宽度、浮动元素和视口标签的配合,以确保网页在各种屏幕尺寸下都能呈现出良好的视觉效果和用户体验。

优化这段代码:List<CompletableFuture<ContactsIntersectionVo>> futureList = intersectionResult.entrySet().stream().map(entry -> CompletableFuture.supplyAsync(() -> { String account = entry.getKey(); List<String> personNoList = entry.getValue().stream().distinct().collect(Collectors.toList()); if (personNoList.size() >= 2) {// 取两个以上的交集 List<Map<String, Object>> remarkList = Lists.newArrayList(); List<PersonBasicVo> personVoList = Lists.newArrayList(); // 获取备注、涉案人 for (String personNo : personNoList) { Map<String, Object> contactsMap = contactsMapList.stream().filter(map -> personNo.equals(map.get("personNo"))).findAny().get(); List<ContactsBasic> contactsList = (List<ContactsBasic>) contactsMap.get("contactsList"); // 获取备注 for (ContactsBasic contacts : contactsList) { if (account.equals(contacts.getRelationshipAccount())) { PersonBasicVo personBasic = personList.stream().filter(person -> personNo.equals(person.getPersonNo())).findAny().get(); Map<String, Object> remarkMap = new HashMap<>(); remarkMap.put("name", personBasic.getName()); remarkMap.put("remark", contacts.getRelationshipName()); remarkList.add(remarkMap); break; } } // 获取涉案人 personVoList.add(personList.stream().filter(person -> personNo.equals(person.getPersonNo())).findAny().get()); } // 共同号码是否属于涉案人 String commonPersonName = getCommonPersonName(personList, account); ContactsIntersectionVo contactsVo = new ContactsIntersectionVo(); contactsVo.setRemarks(remarkList); contactsVo.setPersons(personVoList); contactsVo.setCommonAccount(account); contactsVo.setCommonPersonName(commonPersonName); return contactsVo; } else { return null; } }, executor)).collect(Collectors.toList()); contactisVoList.addAll(futureList.stream().map(CompletableFuture::join) .filter(Objects::nonNull) .collect(Collectors.toList()));

2023-07-13 上传

优化这段代码:List<CompletableFuture<CallIntersectionVo>> futureList = Lists.newArrayList(); for (Map.Entry<String, List<String>> entry : intersectionResult.entrySet()) { CompletableFuture<CallIntersectionVo> future = CompletableFuture.supplyAsync(() -> { String account = entry.getKey(); List<String> personNoList = entry.getValue().stream().distinct().collect(Collectors.toList()); CallIntersectionVo vo = new CallIntersectionVo(); if (personNoList.size() >= 2) { List<PersonBasicVo> personVoList = Lists.newArrayList(); int count = 0; for (String personNo : personNoList) { Map<String, Object> callMap = callMapList.stream().filter(map -> personNo.equals(map.get("personNo"))).findAny().get(); List<CallRecord> callList = (List<CallRecord>) callMap.get("callList"); // 统计通话频率 count += callList.stream().filter(x -> account.equals(x.getRelationshipAccount())).count(); // 获取涉案人 personVoList.add(personList.stream().filter(person -> personNo.equals(person.getPersonNo())).findAny().get()); } // 共同号码是否属于涉案人 String commonPersonName = getCommonPersonName(personList, account); if (frequency != null && frequency > 0) { if (count >= frequency) { vo.setPersons(personVoList); vo.setCommonAccount(account); vo.setFrequency(count); vo.setCommonPersonName(commonPersonName); } return vo; } else { vo.setPersons(personVoList); vo.setCommonAccount(account); vo.setFrequency(count); vo.setCommonPersonName(commonPersonName); return vo; } } else { return vo; } }, executor); futureList.add(future); } voList.addAll(futureList.stream().map(CompletableFuture::join) .distinct().sorted(Comparator.comparing(vo -> vo.getPersons().size())) .collect(Collectors.toList()));

2023-07-13 上传