android LinearLayout android:layout_weight 作用,固定比例
android 中的 LinearLayout 是线性布局有水平布局horizontal 垂直布局vertical 。本文针对 水平布局horizontal 布局的weight属性做一个标记,以免以后忘记。
android:layout_weight 理解比元素所占有的比重。
一、如果直接只给linearLayout中的元素添加 android:layout_weight = 多少值
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="TextView11111" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="TextView2222222222" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView33" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
二、把android:layout_width="0dp" 设置为0 真正起作用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="TextView11111" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="TextView2222222222" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView33" />
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
三、note:
如上文所示:如果直接添加android:layout_weight属性,不把with设置为0dp的话起不到效果,如果把android:layout_with属性直接删除的话不会报错但是运行的时候会错误。
另:android:layout_weight 属性以比重,比例理解,数值越大分配的控件越多
android LinearLayout android:layout_weight 作用,固定比例的更多相关文章
- Android LinearLayout的android:layout_weight属性
本文主要介绍Android LinearLayout的android:layout_weight属性意义 android:layout_weight为大小权重,相当于在页面上显示的百分比,它的计算是根 ...
- 关于android LinearLayout的比例布局(转载)
关于android LinearLayout的比例布局,主要有以下三个属性需要设置: 1,android:layout_width,android:layout_height,android:layo ...
- Android UI: LinearLayout中layout_weight 属性的使用规则
首先来查看android sdk文档,有这么一段话 LinearLayout also supports assigning a weight to individual children with ...
- android LinearLayout
Android的布局方式共有6种,分别是LinearLayout(线性布局).TableLayout(表格布局).FrameLayout(帧布局).RelativeLayout(相对布局).GridL ...
- android设置组件所占的比例
当我们使用linearlayout线性布局,放置三个textview空间,设置android:layout_width属性为wrap_content,并分别设置android:layout_weigh ...
- [Android] Android 让UI控件固定于底部的几种方法
Android 让UI控件固定于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_p ...
- Android linearlayout常用布局
用linearlayout完成这样的布局效果,这样的布局还是比较常用的,具体的xml代码如下: <LinearLayout xmlns:android="http://schemas. ...
- Android LinearLayout整个布局设置不可点击
1,activity的xml布局(布局中有个Button按钮,点击按钮弹出一个popupwindow ) <?xml version="1.0" encoding=" ...
- 关于Android LinearLayout添加分隔线的方法
目前了解的办法有两个:1.自定义一个view当作分隔线:2.使用高版本的分隔线属性 一.在需要添加分隔线的地方,添加一个view,比如ImageView,TextView等都可以,如代码,关键是设置高 ...
随机推荐
- oracle系统参数修改
create pfile='/home/oracle/sss.ora' from spfile; create spfile from pfile='/home/oracle/sss.ora'; al ...
- Windows下的窗口程序
再进一步. . .model flat,stdcall option casemap:none include Windows.inc include user32.inc includelib us ...
- 关于 zend studio 中有些php 内置函数没有提示,或是有‘小黄色感叹号’
解决办法: 1.修改项目 .buildpath 文件 <?xml version="1.0" encoding="UTF-8"?> <buil ...
- Android 相对布局常用属性
Android 布局属性详解 RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 ...
- JNDI(转载)
转自:http://javacrazyer.iteye.com/blog/759485 原理: 在DataSource中事先建立多个数据库连接,保存在数据库连接池中.当程序访问数据库时 ...
- PTF在PET上印刷線路的注意事項
PTF: Polymer Thick Film (聚合厚模),維基的解釋 PET: Polyethylene terephthalate (聚乙烯對苯二甲酸酯),維基的解釋 就如同大家所知道的,相較於 ...
- 以前用Delphi写的CSDN免积分下载器
用了AlphaControl皮肤组件,原理很简单,就是CSDN的一个漏洞.我主要是使用WinInet来获取相关信息,然后从里面分析出真实的下载URL,同时我也是用了AES加密.function Get ...
- Unicode其实是Latin1的扩展。只有一个低字节的Uncode字符其实就是Latin1字符——附各种字符编码表及转换表
一.概念 1,ASCII ASCII(American Standard Code for Information Interchange),中文名称为美国信息交换标准代码.是 ...
- linux下监视进程 崩溃挂掉后自动重启的shell脚本
如何保证服务一直运行?如何保证即使服务挂掉了也能自动重启?在写服务程序时经常会碰到这样的问题.在Linux系统中,强大的shell就可以很灵活的处理这样的事务. 下面的shell通过一个while-d ...
- TCP/IP Checksum 吐槽
算法原理: 假定 output[2] 为输出结果,input[n]为待计算校验和的内存块. 1)所有奇数位[0,2,4……] byte 累加进 结果的奇数位内存 output[0],如果溢出,则进位给 ...