首先说的是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实现垂直水平居中布局的更多相关文章

  1. Andriod中textview垂直水平居中及LinearLayout内组件的垂直布局

    1.textview 垂直水平居中的设置 Android:gravity="center_vertical|center" 2.LinearLayout中设置控件垂直布局,默认的是 ...

  2. 实现LinearLayout(垂直布局,Gravity内容排布)

    首先上Gravity的代码,Android原版的Gravity搞得挺复杂的,太高端了.但基本思路是使用位运算来做常量,我就自己消化了一些,按自己的思路来实现. 先上代码,在做分析. package k ...

  3. Android中的LinearLayout布局

    LinearLayout : 线性布局 在一般情况下,当有很多控件需要在一个界面列出来时,我们就可以使用线性布局(LinearLayout)了,  线性布局是按照垂直方向(vertical)或水平方向 ...

  4. [android]如何使LinearLayout布局从右向左水平排列,而不是从左向右排列

    方法1: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:l ...

  5. 使用Sass优雅并高效的实现CSS中的垂直水平居中(附带Flex布局,CSS3+SASS完美版)

    实现css水平垂直居中的方法有很多,在这里我简单的说下四种比较常用的方法: 1.使用CSS3中的Flex布局 对于flex,我们要了解的是它是一个display的属性,而且必须要给他的父元素设置fle ...

  6. [Android学习笔记]LinearLayout布局,剩余空间的使用

    转自:http://segmentfault.com/q/1010000000095725 如果使得一个View占用其父View的剩余空间? 答案是使用:android:layout_weight = ...

  7. 三、Android学习第三天——Activity的布局初步介绍(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 三.Android学习第三天——Activity的布局初步介绍 今天总结下 ...

  8. 【转】Android开发学习笔记:5大布局方式详解

    Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...

  9. 【Android 应用开发】AndroidUI设计之 布局管理器 - 详细解析布局实现

    写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...

  10. Android 手机卫士--导航界面1的布局编写

    本文地址:http://www.cnblogs.com/wuyudong/p/5943005.html,转载请注明出处. 本文实现导航界面1的布局的实现,效果如下图所示: 首先分析所使用的布局样式: ...

随机推荐

  1. Windows 触控笔

    平板以及二合一平板均是触控屏,Laptop现在也有很多屏幕带触控 触控屏,都会配置触控笔配件,目前市场上一般是电容屏+电容笔的技术方案. 触控笔分为主动笔和被动笔,主动笔占绝大部分.主动笔是通过内部电 ...

  2. 获取Map中选择的要素

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  3. element-ui el-dialog中套el-dialog被遮罩遮盖的问题

    添加 append-to-body 属性 具体见官方文档 入口

  4. 一款基于 .NET MVC 框架开发、功能全面的MES系统

    前言 今天大姚给大家分享一款基于 .NET MVC 框架开发.功能全面的离散型零部件制造管理系统(MES):EasyMES. 项目介绍 EasyMES一款基于 .NET 6 MVC 框架开发.开源免费 ...

  5. NoSQL 述评

    作为主库的 nosql 只有 CockroachDB.TiKV 以及 MongoDB(从4.0后事务似乎可用了),CockrouchDB 已经收费,另外 YugabyteDB 也可选,但大家的反馈都不 ...

  6. TeamViewer 的替代品 ZeroTier + NoMachine

    之前不怎么用 TeamViewer,最近用的多了,特别好用,有点上瘾,在哪儿都能连家里的 RTX,太棒了. 然后它就开始作了. 有没有好的替代方案呢?有人推荐向日葵,向日葵显然是以盈利为目的的我不想再 ...

  7. 关于Qt选择qml还是widget的深度思考

    在Qt界始终有两大阵营产生激烈的纷争,那就是选用qml还是widget好,大量初学者也会问这个问题,有以下几点总结. widget属于传统界面开发,和VB/VC/Delphi等拖曳控件开发类似,走CP ...

  8. 内华达大地测量实验室gnss数据半自动化下载

    内华达大地测量实验室GNSS数据半自动化下载 前言 目的:继上篇GNSS时序形变位移数据下载,介绍了内华达网站GNSS位移数据如何手动交互进行下载.后面发现若自己需要下载很多站点的数据,我要通过手动一 ...

  9. macOS安装编译pcl

    macOS安装编译pcl git clone git@github.com:PointCloudLibrary/pcl.git cd pcl brew install eigen brew insta ...

  10. 【量化读书笔记】【打开量化投资的黑箱】Ch.03 阿尔法模型:Qunat如何盈利?

    阿尔法模型非常规定义:在交易中关于买卖时机把握和持有头寸选择的技巧. 阿尔法是指扣除市场基准回报之后的投资回报率. 一.两类阿尔法模型:理论驱动型和数据驱动型 1.1理论驱动型阿尔法模型 基于价格数据 ...