当前位置: 首页 > news >正文

android orientation框架,LinearLayout布局简单介绍

LinearLayout android中常用的线性布局

可以根据屏幕的大小自动调节控件

下面对LinearLayout的几个属性做简单的介绍

1、android:orientation属性:

即排列方式,可以选择横排或竖排(horizontal,vertical)

vertical:垂直排列

horizontal:水平排列

举个例子:

比如我们要在一个界面中做一个3x3

即3行3列的按钮

那么在主LinearLayout中我们通常用垂直布局即(android:orientation="vertical")

在主框架中我们再添加三个子框架,子框架中采用水平布局(android:orientation="horizontal")

2、控制子框架之间的距离

通常用 android:layout_margin..(包括上下左右)

如android:layout_marginTop="20dp"即距离上个控件20dp

3、控件按比例排列

有些时候,对于某些空间我们不想让其占据太多位置,当然对于固定的机型屏幕可以设置给它固定的

大小,但是屏幕适配是不合格的

在这里我们就需要用到了android:layout_weight=""属性

如在一行显示两个控件一个TextView、另一个EditText

我们需要让EditText占据更多的空间这里我们选择1:2

于是在TextView的属性中我们设置为(android:layout_weight="1")

同样在EditText中设置属性为(android:layout_weight="2")

前提是该子框架中只有这两个控件。

以上即是LZ对LinearLayout的简单理解

如有不懂或错误之处,欢迎给出建议!!!

贴出主要布局代码<?xml  version="1.0" encoding="utf-8"?>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:id="@+id/textView1"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:text="@string/name" />

android:id="@+id/editText1"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="2" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:orientation="horizontal" >

android:id="@+id/textView2"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:text="@string/num" />

android:id="@+id/editText2"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="2"

android:ems="10" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:orientation="horizontal" >

android:id="@+id/button2"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button" />

android:id="@+id/button1"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Button" />

9aac164751f4f43158b5377f82a69de7.png

相关文章:

  • html页面c标签替换,HTML常用标签,什么是空标签和可替换标签
  • 响应式编程html,函数式响应式编程 - Functional Reactive Programming-Go语言中文社区
  • 纯html无限级目录树,利用Ajax实现无限级目录树(.NET)[转载]
  • 微型计算机自动化控制专业,你也能考国家电网之自动控制类专业!
  • 计算机与现代教育的英语作文,雅思写作大作文范文:电脑与现代教育
  • 五年级英语短文计算机,有关于计算机的英语短文章
  • h5怎么引入html,在html文件引入其它html文件的几种方法
  • html排行榜代码手机版,移动端前端代码优化丨排名VS体验
  • 计算机应用技术教程试题大一,大一计算机导论期末考试试题模拟试题及答案
  • 嵌入式计算机技术分类,嵌入式系统的分类及应用
  • 初中计算机课程图文混排教案,七年级信息技术教案:图文的混合编排
  • 天津城建大学计算机学院官网,天津城建大学计算机与信息工程学院研究生导师简介-杨振舰...
  • 计算机文化基础的改革,计算机学生论文,关于对计算机文化基础课程改革相关参考文献资料-免费论文范文...
  • 鲁迅美术学院考计算机几级,鲁迅美术学院英语四级考试科目安排2020年上半年...
  • 计算机实验圆述职报告,实验员个人述职报告(三)
  • 【跃迁之路】【735天】程序员高效学习方法论探索系列(实验阶段492-2019.2.25)...
  • 03Go 类型总结
  • Akka系列(七):Actor持久化之Akka persistence
  • dva中组件的懒加载
  • ES6, React, Redux, Webpack写的一个爬 GitHub 的网页
  • Git初体验
  • Golang-长连接-状态推送
  • open-falcon 开发笔记(一):从零开始搭建虚拟服务器和监测环境
  • Python连接Oracle
  • React 快速上手 - 06 容器组件、展示组件、操作组件
  • 关于 Cirru Editor 存储格式
  • 你真的知道 == 和 equals 的区别吗?
  • 扑朔迷离的属性和特性【彻底弄清】
  • mysql 慢查询分析工具:pt-query-digest 在mac 上的安装使用 ...
  • 从如何停掉 Promise 链说起
  • # centos7下FFmpeg环境部署记录
  • #git 撤消对文件的更改
  • (html转换)StringEscapeUtils类的转义与反转义方法
  • (javascript)再说document.body.scrollTop的使用问题
  • (PHP)设置修改 Apache 文件根目录 (Document Root)(转帖)
  • (八)Docker网络跨主机通讯vxlan和vlan
  • (免费领源码)Python#MySQL图书馆管理系统071718-计算机毕业设计项目选题推荐
  • (学习日记)2024.04.04:UCOSIII第三十二节:计数信号量实验
  • (译) 理解 Elixir 中的宏 Macro, 第四部分:深入化
  • (转)负载均衡,回话保持,cookie
  • ***详解账号泄露:全球约1亿用户已泄露
  • .L0CK3D来袭:如何保护您的数据免受致命攻击
  • .Net core 6.0 升8.0
  • .NET Core工程编译事件$(TargetDir)变量为空引发的思考
  • .net Stream篇(六)
  • .NET 的程序集加载上下文
  • @RequestMapping-占位符映射
  • []新浪博客如何插入代码(其他博客应该也可以)
  • [Angular] 笔记 6:ngStyle
  • [ASP.NET MVC]Ajax与CustomErrors的尴尬
  • [C++参考]拷贝构造函数的参数必须是引用类型
  • [EFI]MSI GF63 Thin 9SCXR电脑 Hackintosh 黑苹果efi引导文件
  • [HAOI2016]食物链
  • [InnoDB系列] -- SHOW INNODB STATUS 探秘
  • [Oh My C++ Diary]带参数的main()函数