Android布局_布局概述和LinearLayout布局
一、布局概述:
布局为UI提供了一个可视化的结构,比如对于一个activity或者app widget的UI,你可以用两种方式声明布局:
在XML中声明UI元素
在运行时实例化布局元素(在java代码中去写布局)
布局之间可以相互嵌套

二、LinearLayout概述:
LinearLayout是线性布局控件,它包含的子控件将横向或竖向的方式排列


三、LinearLayout属性:
1、android:orientation = ""
该属性决定他子类控件的排布方式(vertical:垂直;horizontal:水平)
2、android:gravity = ""
该属性决定他所有子类的xy的位置,多个属性可以一起用(android:gravity="bottom|right"),常用到的几个属性值:
center_vertical:垂直(Y抽居中)
center_horizontal:水平(X抽居中)
center:水平垂直都居中
right:子类控件位于当前布局的右边
left:子类控件位于当前布局的左边
bottom:子类控件位于当前布局的下面
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom|right" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> <Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> </LinearLayout>
3、子类控件在LinearLayout中常用到的属性
android:layout_gravity = "bottom" ------指本身在当前父容器的XY的一个位置,这个属性注意的地方:
这个属性的属性值跟android:gravity = ""是一样的
有时候这个属性达不到你想要的效果,那么就用布局中的android:gravity = ""去控制
需要结合线性布局中的android:orientation="vertical"属性一起使用,这个属性的值不同会有不同的效果
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <Button
android:layout_gravity="center_horizontal"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> </LinearLayout>
android:layout_weight = "1" -------指本身控件占当前父容器的一个比例
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="2" /> <Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" /> </LinearLayout>
四、布局的嵌套
布局之间可以嵌套,就是一个布局里面可以在加多一个或多个布局(任意布局都可以,线性布局也可以嵌套相对布局)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/> <Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" > <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="2" /> <Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" /> </LinearLayout> </LinearLayout>
Android布局_布局概述和LinearLayout布局的更多相关文章
- Android学习——LinearLayout布局实现居中、左对齐、右对齐
android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一 ...
- [android]如何使LinearLayout布局从右向左水平排列,而不是从左向右排列
方法1: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:l ...
- Android:LinearLayout布局中Layout_weight的深刻理解
首先看一下LinearLayout布局中Layout_weight属性的作用:它是用来分配属于空间的一个属性,你可以设置他的权重.很多人不知道剩余空间是个什么概念,下面我先来说说剩余空间. 看下面代码 ...
- 【Android UI】Android开发之View的几种布局方式及实践
引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...
- Android 开发:view的几种布局方式及实践
View的几种布局显示方法,以后就不会在针对布局方面做过多的介绍.View的布局显示方式有下面几种:线性布局(Linear Layout).相对布局(Relative Layout).表格布局(Tab ...
- Android开发:View的几种布局及实践
引言 View的布局显示方式有下面几种:线性布局(Linear Layout).相对布局(Relative Layout).表格布局(Table Layout).网格视图(Grid View).标签布 ...
- Android新手入门2016(7)--布局
布局,这个在服务端变成是没有的,也是服务端的人学习client的一道坎吧. 曾经用cocos2d-x写小游戏的时候就是这个非常难懂,或者能用,可是理解不多的话,非常难写出好的布局,难以适合商业化的应用 ...
- 三、Android学习第三天——Activity的布局初步介绍(转)
(转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 三.Android学习第三天——Activity的布局初步介绍 今天总结下 ...
- Android四大组件之Activity(活动)及其布局的创建与加载布局
Android四大组件之Activity(活动)及其布局的创建与加载布局 什么是Activity ? 活动(Activity)是包含用户界面的组件,主要用于和用户进行交互的,一个应用程序中可以包含零个 ...
随机推荐
- java对象equals方法的重写
根类Object中的equals方法描述: public boolean equals(Object obj)The equals method for class Object implements ...
- Poj(3615),Floyd,最大值中的最小值
题目链接:http://poj.org/problem?id=3615 题意:大致题意:有N个木桩,和M个木桩对之间的高度差(从x跳到y需要往上跳的高度).从x跳跃到y的路径消耗的体力值是路径中的一个 ...
- C#中通过Selenium IWebDriver实现人人网相册备份工具
我用Selenium写了一个人人网相册备份工具,亲测通过. 需要输入你的用户名.密码.相册地址. 代码如下: using System; using System.Collections.Generi ...
- java实现多线程断点续传,上传下载
采用apache 的 commons-net-ftp-ftpclient import java.io.File; import java.io.FileOutputStream; import ja ...
- 【LTE基础知识】SGLTE, SVLTE, CSFB, VoLTE
4G网络下实现语音通话功能的技术共有三种--VoLTE.SGLTE(GSM /LTE同步并发)和CSFB(电路域回落).简单来说: VoLTE就是语音数据都在4G通道内完成: SGLTE是语音走2G通 ...
- Windows7下安装搭建Ngnix教程
简介: Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 服务器. Nginx 是由 Igor Syso ...
- .Net验证码实现基础--Draw
命名空间 using System.Draw; using System.Draw.Drawing2D; 在form等控件的 事件中 添加 paint事件 ///////画各种形状(空心)////// ...
- Win7 winsock 注册表文件
http://files.cnblogs.com/xsmhero/Winsock_Win7x64.rar
- zoj 1453 Surround the Trees(凸包求周长)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds Memory ...
- GBASE结构理解
GBASE数据库 8a 8a Cluster 8t 8m BI 8d 8 分析型数据库 分布式并行数据库集群 高端事务性数据库 高速内存数据库 可视商业智能 大型目录服务体系 硬加密安全数据库 数据分 ...