Android基础TOP3:线性布局的特点,常用属性,及权重值
线性布局是一种让视图水平或者垂直布排列的布局;
常用属性:
androuid:orientation :表示布局方向
- 取值vertical表示垂直布局
- 取值horizontal表示水平布局
android:gravity 表示视图对齐方式
- 内容包括 TOP,bottom,left,right,center_vertical,center_horizontal,center
- 可以使用“|”分割填写多个值
布局中的视图可以使用如下多个属性:
android:layout_gravity 表示单个视图的对齐方式
android:layout_weight 表示单个视图所在大小的比重
- 当Layout_weight为0时候视图大小自身确定
- 当layout_weight大于0时,视图在线性布局方向根据比重拉伸
代码演示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:layout_width="200dp"
android:layout_height="100dp"
android:text="adaflkjn"
android:gravity="bottom|center_horizontal"/> </LinearLayout>

android:gravity:是决定控件内元素在某个位置
<Button
android:layout_width="200dp"
android:layout_height="100dp"
android:text="adaflkjn"
android:layout_gravity="center"/>

android:layout_gravity是本元素在父元素里面显示的位置
weight的应用
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="sdaf"/>
<Button
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="klndgjl"
/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="weight为0"
android:background="#FFF0F5"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="weight为1"
android:layout_weight="1"
android:background="#800080"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="weight为4"
android:layout_weight="4"
android:background="#4B0082"
/>

Android基础TOP3:线性布局的特点,常用属性,及权重值的更多相关文章
- android基础学习之布局
我学习android第一步接触的就是布局的学习.布局是androidUI的基础,是重中之重.总的来说android有6种布局,分别是线性布局LinearLayout.相对布局RelativeLayou ...
- Android基础TOP3:Activity的线性,相对,帧和表格布局的概括
线性布局 LinearLayout: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...
- Android 自学之线性布局 LinearLayout
线性布局(LinearLayout),线性布局有点想AWT编程里面的FolwLayout,他们都会将容器里面的组件挨个的排列起来. 他们最大的区别在于:Android的线性布局不会换行:AWT里面的F ...
- 【Android】7.1 布局控件常用的公共属性
分类:C#.Android.VS2015: 创建日期:2016-02-10 一.简介 Android应用程序中的布局控件都是容器控件,用于控制子元素的排列和放置方式.Android提供的布局控件有: ...
- android 59 LinearLayout 线性布局
##常见的布局* LinearLayout 线性布局线性布局往左右拉是拉不动的,> 线性布局的朝向 vertical|horizontal> 线性布局的权重 weight 和 0dip一起 ...
- Android开发之线性布局详解(布局权重)
布局权重 线性布局支持给个别的子视图设定权重,通过android:layout_weight属性.就一个视图在屏幕上占多大的空间而言,这个属性给其设 定了一个重要的值.一个大的权重值,允许它扩大到填充 ...
- .Net程序猿玩转Android开发---(6)线性布局LinearLayout
LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...
- Android之Linearlayouy线性布局
写了个小例子xml代码如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout x ...
- android学习之线性布局
效图如下 移通152余继彪 该布局使用了线性布局完成 父布局为线性布局,黄色和灰色部分为水平的线性布局,剩余50%部分为水平线性布局,该布局中包含了两个垂直的线性布局分别占了三分之1和三分之二
随机推荐
- [Tue, 11 Aug 2015 ~ Mon, 17 Aug 2015] Deep Learning in arxiv
Image Representations and New Domains inNeural Image Captioning we find that a state-of-theart neura ...
- iPhone开发关于UDID和UUID的一些理解【转】
原文地址:http://blog.csdn.net/xunyn/article/details/13629071 一.UDID(Unique Device Identifier) UDID是Uniqu ...
- TPC-H is a Decision Support Benchmark
TPC-H is a Decision Support Benchmark http://www.dba-oracle.com/t_tpc_benchmarks.htm
- css中vertical-align和line-height的用法
css中vertical-align和line-height的用法 1.先来看一种现象: (1).将一个图片放入一个div块中,div块背景颜色设置为aquamarine.将会发现图片与div块下边沿 ...
- mysql17---增量备份
mysql增量备份: 全备份是: (增量备份一定要看日志的时间和位置节点) mysql数据库会以二进制的形式,把用户对mysql数据库的操作记录到文件中,不用使用定时器了.当用户希望恢复的时候,可以使 ...
- POJ3020 Antenna Placement —— 最大匹配 or 最小边覆盖
题目链接:https://vjudge.net/problem/POJ-3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K ...
- bzoj1044 [HAOI2008]木棍分割——前缀和优化DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1044 咳咳...终于A了... 居然没注意到正着找pos是n方会TLE...所以要倒着找po ...
- 关于CentOS 7安装solr+tomcat
1.Solr7.1.0 安装部署(centos7) Solr7.1.0为目前的最新版,安装环境需要jdk1.8 或者更高,容器我用的tomcat,也建议tomcat8.0或者更高 1.1.下载solr ...
- bzoj 5281: [Usaco2018 Open]Talent Show【dp】
注意到sum_t比较小,所以设f[i][j]为选前i头牛,当前sum_t为j的最小sum_w值,转移是f[i][j]=min(f[i-1][j],f[i-1][j-t[i]]+w[i]),然后i维用滚 ...
- bzoj 1179: [Apio2009]Atm【tarjan+spfa】
明明优化了spfa还是好慢-- 因为只能取一次值,所以先tarjan缩点,把一个scc的点权和加起来作为新点的点权,然后建立新图.在新图上跑spfa最长路,最后把酒吧点的dis取个max就是答案. # ...