Android应用借助LinearLayout实现垂直水平居中布局
首先说的是LinearLayout布局下的居中一般是这样的:
(注意:android:layout_width="fill_parent" android:layout_height="fill_parent" 属性中,若水平居中,至少在宽度上占全屏;若垂直居中,则在高度上占全屏)
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center|center_horizontal|center_vertical" >
// 上面gravity属性的参数:center为居中,center_horizontal为水平居中,center_vertical为垂直居中
<Button
android:id="@+id/Binding_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="关联新账户" />
</LinearLayout>
要实现垂直水平居中,几个基本参数值得注意:
1、android:orientation="vertical"表示该布局下的元素垂直排列;
2、android:layout_gravity="center_horizontal"表示该布局在父布局里水平居中,此时其父布局必须拥有android:orientation="vertical"属性;
3、android:layout_gravity="center_vertical"表示该布局在父布局里垂直居中,此时其父布局必须应设置成android:orientation="horizontal"属性(默认为该属性),且其父布局的高度应设置为android:layout_height="fill_parent"属性;
4、android:gravity="center_horizontal"表示该布局下的元素水平居中;
线性布局垂直水平居中布局文件实例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical"
> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="用户名" /> <EditText
android:layout_width="300dp"
android:layout_height="wrap_content" />
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Email" /> <EditText
android:layout_width="300dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Android应用借助LinearLayout实现垂直水平居中布局的更多相关文章
- Andriod中textview垂直水平居中及LinearLayout内组件的垂直布局
1.textview 垂直水平居中的设置 Android:gravity="center_vertical|center" 2.LinearLayout中设置控件垂直布局,默认的是 ...
- 实现LinearLayout(垂直布局,Gravity内容排布)
首先上Gravity的代码,Android原版的Gravity搞得挺复杂的,太高端了.但基本思路是使用位运算来做常量,我就自己消化了一些,按自己的思路来实现. 先上代码,在做分析. package k ...
- Android中的LinearLayout布局
LinearLayout : 线性布局 在一般情况下,当有很多控件需要在一个界面列出来时,我们就可以使用线性布局(LinearLayout)了, 线性布局是按照垂直方向(vertical)或水平方向 ...
- [android]如何使LinearLayout布局从右向左水平排列,而不是从左向右排列
方法1: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:l ...
- 使用Sass优雅并高效的实现CSS中的垂直水平居中(附带Flex布局,CSS3+SASS完美版)
实现css水平垂直居中的方法有很多,在这里我简单的说下四种比较常用的方法: 1.使用CSS3中的Flex布局 对于flex,我们要了解的是它是一个display的属性,而且必须要给他的父元素设置fle ...
- [Android学习笔记]LinearLayout布局,剩余空间的使用
转自:http://segmentfault.com/q/1010000000095725 如果使得一个View占用其父View的剩余空间? 答案是使用:android:layout_weight = ...
- 三、Android学习第三天——Activity的布局初步介绍(转)
(转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 三.Android学习第三天——Activity的布局初步介绍 今天总结下 ...
- 【转】Android开发学习笔记:5大布局方式详解
Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...
- 【Android 应用开发】AndroidUI设计之 布局管理器 - 详细解析布局实现
写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...
- Android 手机卫士--导航界面1的布局编写
本文地址:http://www.cnblogs.com/wuyudong/p/5943005.html,转载请注明出处. 本文实现导航界面1的布局的实现,效果如下图所示: 首先分析所使用的布局样式: ...
随机推荐
- C#微信公众号开发
C#微信公众号开发 一> 准备 [开发文档] [微信公众号测试接口] 用自己的微信扫码登陆,然后就可以获取就有了appId 和 appsecret. 二>获取access_token 打开 ...
- Fiddler抓包iOS手机配置全流程
前情 平时做移动移动端开必的时候经常需要抓包手机,用于接口请求跟踪,但iOS的抓包经常性的配不成功,经过踩过不少坑后终于知道了整个配置流程,此文记录Fiddler抓包iOS手机的配置流程. Step ...
- 【Amadeus原创】SQL Server数据库备份、差异备份、日志备份脚本
1,sp脚本 USE [master] GO /****** Object: StoredProcedure [dbo].[sp_BackupDatabase] Script Date: 2021/1 ...
- HttpClient初步理解
昨天做完网站项目,就立刻接到了接口的项目,遇到了httpclient,因为毕业不久,遇到这块所以特此留下理解 HttpClient介绍 概念: HTTP 协议可能是现在 Internet 上使用得最多 ...
- 【机器学习】SVM(支持向量机)算法实验
(一)实验名称:SVM(支持向量机)算法实验 (二)实验目的: 学习支持向量机SVM的基本概念 了解核函数的基本概念 掌握使用scikit-learn API函数实现SVM算法 (三)实验内容:使用s ...
- 【MyBatis】学习笔记11:解决字段名和属性的映射关系
[Mybatis]学习笔记01:连接数据库,实现增删改 [Mybatis]学习笔记02:实现简单的查 [MyBatis]学习笔记03:配置文件进一步解读(非常重要) [MyBatis]学习笔记04:配 ...
- 虚拟机安装 Win10 ,无法启动,报错EFI Network ... Time out
问题情况 VMWare 16 安装 win10 的镜像文件,无法启动,报错 EFI Network ... Time out 解决办法 虚拟机设置中 固件类型 改用 BIOS 已解决
- Socket、Http、WebSocket?强大的Netty几行语句就帮你实现!
一.概述 Netty是目前最流行的由JBOSS提供的一个Java开源框架NIO框架,Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开发高性能.高可靠性的网络服务器和客户端程序. 相比 ...
- spring boot 启动原理解析
https://www.cnblogs.com/xiaoxi/p/7999885.html 我们开发任何一个Spring Boot项目,都会用到如下的启动类 1 @SpringBootApplicat ...
- MySQL said: Authentication plugin 'caching_sha2_password' cannot be loaded
OUTLINE问题描述解决方案问题描述在mac下,用sequel pro连接数据库,出现以下问题: MySQL said: Authentication plugin 'caching_sha2_pa ...