Android开发之layout_weight属性的应用
来源:互联网 发布:20毫米机炮弹药数据 编辑:程序博客网 时间:2024/05/22 00:26
在Android开发过程中,Android开发者之间的交流学习是互通开源的。关于Android开发中layout布局文件中常用到的属性,有很多小盆友不了解,今天eoeandroid开发论坛(http://www.eoeandroid.com/)就来为童鞋们整理分享如下内容:
在layout布局文件中经常用到android:layout_width、android:layout_width及android:layout_weight这些属性。那么android:layout_weight代表什么呢?不要译为体重,重量。Weight也可表示比重、权重,这在测量学中比较常见。
默认值为0,即视图大小与屏幕空间大小相等,屏幕有多大,视图就有多大。如果将其设为大于0的数值,则将父视图的可用空间分割,分割大小具体取决于每个视图的layout_weight的值,该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。
打个比方,水平布局有两个图片,一个图片值为1,另一个图片值也为1,则两者平分视图;或者一个图片值为1,另一个图片值为2,则第一个图片所占视图为2/3,第二张图片所占视图为1/3。
1、代码:
< ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:tint="#33ff9966"
android:src="@drawable/c" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/c" />
效果:
2、代码:在布局文件中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="redwwwwwww"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="2"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="3"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="4"/>
</LinearLayout>
</LinearLayout>
效果:
我不明白这个是怎么布设的,权重又该怎么算。有人明白的话给我指点迷津。
【*Android开发论坛-安卓开发-最活跃的android开发论坛 http://www.eoeandroid.com/】
- Android开发之layout_weight属性的应用
- android之layout_weight属性
- Android属性系列之layout_weight
- Android手机开发:android:layout_weight属性的使用
- android布局之layout_weight应用
- android开发中LinearLayout中的Layout_weight属性的理解
- android:layout_weight属性的使用
- android:layout_weight属性的使用
- Android的layout_weight属性详解
- Android的layout_weight属性释疑
- Android布局的layout_weight属性
- android Layout_weight属性的详解
- Android 布局学习之——LinearLayout的layout_weight属性
- android:layout_weight的巧妙应用
- android开发笔记之android:layout_weight的使用
- Android布局之Layout_weight属性解析
- android属性之layout_weight深入研究
- Android百分比布局之layout_weight属性
- win32中使用CString类型变量
- ACM-贪心之Fat Mouse Trade——hdu1009
- IIS 无法启动错误:"指定的网络名格式无效"
- linux shell基础1.5--数组
- 【游戏】走迷宫游戏分析
- Android开发之layout_weight属性的应用
- 【数据结构之排序1】排序的基本概念
- 使用adb命令卸载Android系统应用
- js访问一个服务获取json数据
- DTD元素详解
- SQL Developer不能删除、回退及其他按键失效问题
- APK签名发布步骤(dos)
- 动态分配二维数组 c++
- 数据库上机实验学习记录最新Day1117