【线性布局和相对布局的加深理解】:练习和见解(图书显示)

2024-05-12 22:38

本文主要是介绍【线性布局和相对布局的加深理解】:练习和见解(图书显示),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

关于线性布局注意内容:
布局中一般RelativeLayout都是在LinearLayout里面,
关于权重weight的加深理解是,weight只有在LinerLayout才能被使用,这是很重要的一点,
RelativeLayout中使用权重weight必须满足条件有:
1.RelativeLayout是在LinearLayout下面进行布局设计
2.LinearLayout必须指定布局方向也就是:android:orientation="vertical"
如果没有指定布局方向的话RelativeLayout使用weight权重也是会出现错误

接下来就是进行设计范围,和基础篇2相同,设计的是图书显示页面:
在这里插入图片描述代码实现如下:


```csharp
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="10dp"android:background="#8492a6"></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><LinearLayoutandroid:orientation="vertical"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:background="#f4f4"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="2"android:background="#7ba8b0"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="此处为图书封面"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="3dp"android:background="#bfd9d4"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="书名"android:textSize="18sp"/></RelativeLayout></LinearLayout><RelativeLayoutandroid:layout_width="3dp"android:layout_height="match_parent"android:background="#7489ab"></RelativeLayout><LinearLayoutandroid:orientation="vertical"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="2"android:background="#bfd9d4"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="概述"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="5dp"android:background="#2e4d5c"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="作者"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="5dp"android:background="#2e4d5c"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="日期"android:textSize="18sp" /></RelativeLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="10dp"android:background="#8492a6"></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><LinearLayoutandroid:orientation="vertical"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:background="#f4f4"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="2"android:background="#7ba8b0"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="此处为图书封面"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="3dp"android:background="#bfd9d4"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="书名"android:textSize="18sp"/></RelativeLayout></LinearLayout><RelativeLayoutandroid:layout_width="3dp"android:layout_height="match_parent"android:background="#7489ab"></RelativeLayout><LinearLayoutandroid:orientation="vertical"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="2"android:background="#bfd9d4"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="概述"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="5dp"android:background="#2e4d5c"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="作者"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="5dp"android:background="#2e4d5c"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="日期"android:textSize="18sp" /></RelativeLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="10dp"android:background="#8492a6"></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><LinearLayoutandroid:orientation="vertical"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:background="#f4f4"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="2"android:background="#7ba8b0"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="此处为图书封面"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="3dp"android:background="#bfd9d4"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="书名"android:textSize="18sp"/></RelativeLayout></LinearLayout><RelativeLayoutandroid:layout_width="3dp"android:layout_height="match_parent"android:background="#7489ab"></RelativeLayout><LinearLayoutandroid:orientation="vertical"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="2"android:background="#bfd9d4"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="概述"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="5dp"android:background="#2e4d5c"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="作者"android:textSize="18sp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="5dp"android:background="#2e4d5c"></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#bfd9d4"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="日期"android:textSize="18sp" /></RelativeLayout></LinearLayout></LinearLayout></LinearLayout>

这篇关于【线性布局和相对布局的加深理解】:练习和见解(图书显示)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/983940

相关文章

从原理到实战深入理解Java 断言assert

《从原理到实战深入理解Java断言assert》本文深入解析Java断言机制,涵盖语法、工作原理、启用方式及与异常的区别,推荐用于开发阶段的条件检查与状态验证,并强调生产环境应使用参数验证工具类替代... 目录深入理解 Java 断言(assert):从原理到实战引言:为什么需要断言?一、断言基础1.1 语

SpringSecurity显示用户账号已被锁定的原因及解决方案

《SpringSecurity显示用户账号已被锁定的原因及解决方案》SpringSecurity中用户账号被锁定问题源于UserDetails接口方法返回值错误,解决方案是修正isAccountNon... 目录SpringSecurity显示用户账号已被锁定的解决方案1.问题出现前的工作2.问题出现原因各

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.

idea中project的显示问题及解决

《idea中project的显示问题及解决》:本文主要介绍idea中project的显示问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录idea中project的显示问题清除配置重China编程新生成配置总结idea中project的显示问题新建空的pr

CSS3 布局样式及其应用举例

《CSS3布局样式及其应用举例》CSS3的布局特性为前端开发者提供了无限可能,无论是Flexbox的一维布局还是Grid的二维布局,它们都能够帮助开发者以更清晰、简洁的方式实现复杂的网页布局,本文给... 目录深入探讨 css3 布局样式及其应用引言一、CSS布局的历史与发展1.1 早期布局的局限性1.2

spring IOC的理解之原理和实现过程

《springIOC的理解之原理和实现过程》:本文主要介绍springIOC的理解之原理和实现过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、IoC 核心概念二、核心原理1. 容器架构2. 核心组件3. 工作流程三、关键实现机制1. Bean生命周期2.

电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案

《电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案》最近有不少兄弟反映,电脑突然弹出“mfc100u.dll已加载,但找不到入口点”的错误提示,导致一些程序无法正... 在计算机使用过程中,我们经常会遇到一些错误提示,其中最常见的就是“找不到指定的模块”或“缺少某个DL

html5的响应式布局的方法示例详解

《html5的响应式布局的方法示例详解》:本文主要介绍了HTML5中使用媒体查询和Flexbox进行响应式布局的方法,简要介绍了CSSGrid布局的基础知识和如何实现自动换行的网格布局,详细内容请阅读本文,希望能对你有所帮助... 一 使用媒体查询响应式布局        使用的参数@media这是常用的

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

深入理解Apache Kafka(分布式流处理平台)

《深入理解ApacheKafka(分布式流处理平台)》ApacheKafka作为现代分布式系统中的核心中间件,为构建高吞吐量、低延迟的数据管道提供了强大支持,本文将深入探讨Kafka的核心概念、架构... 目录引言一、Apache Kafka概述1.1 什么是Kafka?1.2 Kafka的核心概念二、Ka