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

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 Spring的依赖注入理解及@Autowired用法示例详解

《JavaSpring的依赖注入理解及@Autowired用法示例详解》文章介绍了Spring依赖注入(DI)的概念、三种实现方式(构造器、Setter、字段注入),区分了@Autowired(注入... 目录一、什么是依赖注入(DI)?1. 定义2. 举个例子二、依赖注入的几种方式1. 构造器注入(Con

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

深入理解Go语言中二维切片的使用

《深入理解Go语言中二维切片的使用》本文深入讲解了Go语言中二维切片的概念与应用,用于表示矩阵、表格等二维数据结构,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧... 目录引言二维切片的基本概念定义创建二维切片二维切片的操作访问元素修改元素遍历二维切片二维切片的动态调整追加行动态

从原理到实战深入理解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