android中常用的布局管理器(二)
接上篇博客
(3)LinearLayout 线性布局管理器
线性布局管理器是将放入其中的组件按照垂直或水平方向来布局,每一行或每一列只能放一个组件,并且不会换行,当组件排列到窗体的边缘后,后面的组件就不会显示出来。
常用属性:
常用属性:
android:orientation(horizontal 水平,vertical 垂直)
android:gravity(对齐方式) 设置组件的对齐位置
android:layout_witdth(宽) (默认为0,当输入一个大于0 的数字时,每个组件对父容器的剩余空间进行分割)
android:layout_height(高)
android:id
android:background(背景)
案列:
android:orientation="horizontal" 水平线性管理器
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮3"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮4" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮5" />
</>
android:orientation="vertical" 垂直水平管理器
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮3"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮4" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮5" />
</>
android:gravity="center" 设置组件的对其你方式
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮3"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮4" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮5" />
</>
android:layout_weight="1"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
android:layout_weight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
android:layout_weight="1"
/>
</>
(4)FrameLayout 帧布局管理器
帧布局(FrameLayout)在屏幕上开辟了一块区域,在这块区域中可以添加多个子控件,但是所有的子控件都会被对齐到屏幕的左上角。帧布局的大小由其下属子控件中尺寸最大的那个子控 件来控制。如果子控件的大小都一样,同一时刻只能看到最上面的子控件,其他的则被其遮挡(在进行选项卡设计时会用到帧布局)。
注意:在FrameLayout中,子控件是通过栈来绘制的,所以后添加的子控件会被绘制在上层。
FrameLayout继承自ViewGroup类,除了继承自父类的属性和方法,FrameLayout类中也包含了自己特有的一些属性和方法,见下表:
属性名称 | 对应方法 | 描述 |
android:foreground | setForeground(Drawable) | 设置绘制在所有子控件之上的内容 |
android:foregroundGravity | setForegroundGravity(int) | 设置绘制在所有子控件之上内容的gravity属性 |
android中常用的布局管理器(二)的更多相关文章
- android中常用的布局管理器
Android中的几种常用的布局,主要介绍内容有: View视图 RelativeLayout 相对布局管理器 LinearLayout 线性布局管理器 FrameLayout ...
- Android UI组件:布局管理器
为了更好的管理Android应用的用户界面中的组件,Android提供了布局管理器.通过使用布局管理器,Android应用的图形用户界面具有良好的平台无关性.通常,推荐使用布局管理器来管理组件的分布. ...
- Android开发5:布局管理器2(表格布局TableLayout)
版本:Android4.3 API18 学习整理:liuxinming 概念 TableLayout继承了LinearLayout,因此它的本质依然是线性布局管理器. 表格布局采 ...
- Android学习笔记(10).布局管理器
布局管理器的几个类都是ViewGroup派生的,用于管理组件的分布和大小,使用布局管理器能够非常好地解决屏幕适配问题. 布局管理器本身也是一个UI组件,布局管理器能够相互嵌套使用,以下是布局管理器的类 ...
- Android中常用的布局
一般分为5大类. Android中所有的空间第一字母都是大写 1.线性布局 LinearLayout 2.相对布局 RelativeLayout 3.帧布局--分层显示 FrameLayout 4. ...
- Android 中常用的布局
一.线性布局----LinearLayout horizontal 水平 <?xml version="1.0" encoding="utf-8"?& ...
- 四种方式写按钮点击事件和Android 中常用的布局
1.匿名内部类的方式 2.创建一个类实现onClickListener,实现onClick方法,设置控件点击时传一个类的对象 3.让当前类实现onClickListener,设置控件点击事件时传递一个 ...
- 【java】浅析java组件中的布局管理器
这篇博文笔者介绍一下java组件中,常用的布局管理器.java组件中的布局方式有好几十种,所有的这些布局管理器都实现了java.awt.LayoutManager接口.接下来笔者介绍一下常用的5种布局 ...
- Android 布局管理器
为了更好地管理Android应用程序的用户界面组件,Android它提供了一个布局管理.通过使用布局管理,Android具有良好的平台无关的图形用户界面应用程序. 平时,推荐布局管理器来管理分布式组件 ...
随机推荐
- 死磕mysql(6)
再写数据库作业的时候,发现了一个问题,如果存在主键外键的约束,数据就删不掉 --set foreign_key_checks=0; 关掉外键约束 用好了再打开 --set foreign_key_ch ...
- javabst1
(单选题)下列概念中不包括任何实现,与存储空间没有任何关系的是() A)类 B)接口 C)抽象类 D)对象 2.(单选题)HTTP状态码中表示请求资源不存在的是(). A)100 B)200 C)30 ...
- re模块 常用函数
1. findall() 函数 find('正则表达式',‘待匹配的字符串’) #返回匹配到字符串,并存放在列表中 详解见:https://www.cnblogs.com/nbk-zyc/p/1111 ...
- PHP第三方登录——QQ登录
主要内容 简单回顾OAuth协议基本原理 接入QQ登录的前置条件以及开放平台账号申请 引入官方SDK SDK参数配置 SDK核心方法解读 整合QQ登录SDK到Web应用中 SDK优化 调用API的开发 ...
- Python3 (五)函数应用
一.认识函数 在命令行中查看内置函数的方法: 1.先在命令行里输入python 2.help(函数) 二.函数的定义及运行特点 1.函数基本定义: def funcname(parameter_lis ...
- 使用gRPC-Web从浏览器调用.NET gRPC服务
我很高兴宣布通过.NET对gRPC-Web进行实验性支持.gRPC-Web允许从基于浏览器的应用程序(例如JavaScript SPA或Blazor WebAssembly应用程序)调用gRPC. . ...
- vue路由--嵌套路由
静态嵌套路由: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- codewars--js--RGB To Hex Conversion
问题描述: The rgb() method is incomplete. Complete the method so that passing in RGB decimal values will ...
- OpenResty 在马蜂窝广告监测中的应用
马蜂窝技术原创内容,更多干货请订阅公众号:mfwtech 广告是互联网变现的重要手段之一. 以马蜂窝旅游 App 为例,当用户打开我们的应用时,有可能会在首屏或是信息流.商品列表中看到推送的广告.如果 ...
- 关于mac下redis的安装和部署
近来学习scrap分布式,需要用到redis,但以前没接触过,所以记录一下自己的安装过程. 准备:Mac,redis-5.0.4.tar.gz 1.压缩包到官网下(建议下载稳定版)网址:redis.i ...