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

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

相关文章

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

Linux虚拟机不显示IP地址的解决方法(亲测有效)

《Linux虚拟机不显示IP地址的解决方法(亲测有效)》本文主要介绍了通过VMware新装的Linux系统没有IP地址的解决方法,主要步骤包括:关闭虚拟机、打开VM虚拟网络编辑器、还原VMnet8或修... 目录前言步骤0.问题情况1.关闭虚拟机2.China编程打开VM虚拟网络编辑器3.1 方法一:点击还原VM

CSS模拟 html 的 title 属性(鼠标悬浮显示提示文字效果)

《CSS模拟html的title属性(鼠标悬浮显示提示文字效果)》:本文主要介绍了如何使用CSS模拟HTML的title属性,通过鼠标悬浮显示提示文字效果,通过设置`.tipBox`和`.tipBox.tipContent`的样式,实现了提示内容的隐藏和显示,详细内容请阅读本文,希望能对你有所帮助... 效

浅析Python中的绝对导入与相对导入

《浅析Python中的绝对导入与相对导入》这篇文章主要为大家详细介绍了Python中的绝对导入与相对导入的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1 Imports快速介绍2 import语句的语法2.1 基本使用2.2 导入声明的样式3 绝对import和相对i

CSS3 最强二维布局系统之Grid 网格布局

《CSS3最强二维布局系统之Grid网格布局》CS3的Grid网格布局是目前最强的二维布局系统,可以同时对列和行进行处理,将网页划分成一个个网格,可以任意组合不同的网格,做出各种各样的布局,本文介... 深入学习 css3 目前最强大的布局系统 Grid 网格布局Grid 网格布局的基本认识Grid 网

CSS弹性布局常用设置方式

《CSS弹性布局常用设置方式》文章总结了CSS布局与样式的常用属性和技巧,包括视口单位、弹性盒子布局、浮动元素、背景和边框样式、文本和阴影效果、溢出隐藏、定位以及背景渐变等,通过这些技巧,可以实现复杂... 一、单位元素vm 1vm 为视口的1%vh 视口高的1%vmin 参照长边vmax 参照长边re

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

深入理解Apache Airflow 调度器(最新推荐)

《深入理解ApacheAirflow调度器(最新推荐)》ApacheAirflow调度器是数据管道管理系统的关键组件,负责编排dag中任务的执行,通过理解调度器的角色和工作方式,正确配置调度器,并... 目录什么是Airflow 调度器?Airflow 调度器工作机制配置Airflow调度器调优及优化建议最