惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
T
Tailwind CSS Blog
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
A
About on SuperTechFans
L
LangChain Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
G
Google Developers Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
D
Docker
博客园 - 聂微东
博客园 - 司徒正美
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
U
Unit 42

博客园 - maoyu417

Size Classes with Xcode 6 Android viewPage notifyDataSetChanged无刷新 android、apple PUSH 异同比较 同一位置(同一个ImageView)显示不同的图片--level-list (转) (Android实战)界面设计注意事项 给C盘减减肥,让你电脑飞一般速度! 用SQL查看字符串ASCII码 解决union不能order by问题 利用sender的Parent获取GridView中的当前行(转载) gridview固定表头 - maoyu417 - 博客园 将某网站设为主页方法 - maoyu417 - 博客园 DataList分页方法一 - maoyu417 - 博客园 SQL区分大小写——转载 字符串间空格在网页上自动合并 Windows Mobil中解决日期显示不正常的方法 VS升级序列号及升级方法 a标签变灰且不可用 ASP.NET读取XML文件4种方法 超时时间已到。在操作完成之前超时时间已过或服务器未响应。
LinearLayout android:layout_weight的理解
maoyu417 · 2011-07-19 · via 博客园 - maoyu417

一 不正确的理解

将各个view(BUTTON等)的android:layout_weight 看作比例关系在父VIEW中显示。

二 自己的理解

weight是重要性标识,值越大重要性越强。

重要性越强,意味着占据父VIEW剩余空间的能力越强。剩余空间可能很大也可能很小,甚至没有。

三 举例说明证实自己的理解

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" >

<Button android:layout_weight="1" android:id="@+id/btn_ok" android:layout_width="wrap_content" android:text="Button1111111111111111111111111111111" android:layout_height="wrap_content"></Button>

<Button android:layout_weight="2" android:id="@+id/btn_ok2" android:layout_width="wrap_content" android:text="Button2" android:layout_height="wrap_content"></Button>

<Button android:layout_weight="3" android:id="@+id/btn_ok3" android:layout_width="wrap_content" android:text="Button3" android:layout_height="wrap_content"></Button>

</LinearLayout>

btn_ok3重要性最高,所以它占有父view剩余空间能力最强。父view会先紧着btn_ok和btn_ok2显示,这两个view的显示会按其所需要的内容空间进行显示,剩余无论多大的空间都分配给btn_ok3显示。