当前位置: 首页 > ai >正文

MATCH_PARENT与FILL_PARENT:不要做什么和怎么做

下面是它的短:除非要编译升级Froyo(API 8),请立即停止使用FILL_PARENT指定layout_width和layout_height 。
使用MATCH_PARENT 。 它们具有相同的整数值,但FILL_PARENT已被废弃,这个名字本身就是误导。 请使用MATCH_PARENT 。

为什么你应该只使用MATCH_PARENT
好吧,如果你还在读书,然后我假设你是不是对编译和升级Froyo,要么你不明白或者不跟我暂时就这么下来同意FILL_PARENT 。

所以MATCH_PARENT和FILL_PARENT是一样的吗?
是的,  MATCH_PARENTFILL_PARENT是相同的整数值用于指定一个不同的只是常量名(如果你是好奇-1) View其父项内的布局模式。

那么,为什么MATCH_PARENT加入?
Android团队发现,开发商被曲解FILL_PARENT意味着一个View将填补留在其父的剩余空间。 事实上,通过指定FILL_PARENT ,该View请求应象大是其父母。
因此,(如在解释罗曼盖伊自己 这段视频在10:56左右)不断更名MATCH_PARENT澄清其使用。

好吧,我得怎么FILL_PARENT / MATCH_PARENT工作。 这有什么关系,如果我使用一个或另一个?
FILL_PARENT已经过时了。 被弃用并不能使它魔鬼,但最终还是会自行消失。 你的应用程序是使用更多面向未来的MATCH_PARENT 。 为什么要使用过时的选项时,
当前选项的行为完全相同?
此外, FILL_PARENT实际上是误导性的。 我曾亲眼见过人们混淆,因为它不工作,他们想的那样的方式。 事实上,我已经看到了同时使用一个
标签FILL_PARENT和MATCH_PARENT ,因为开发人员认为(可以理解),它们是两个不同的布局模式。
是最新的。 是明确的。 使用MATCH_PARENT 。


如何你可以得到绊倒了试图FILL_PARENT
这里有一个如何一个简单的例子MATCH_PARENT / FILL_PARENT混乱可能导致人反复运用他们的头到自己的办公桌。 首先,服用含有几个一个非常简单的布局View实例。
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.               android:layout_width="match_parent"
  3.               android:layout_height="match_parent"
  4.               android:orientation="vertical">       
  5.     <View
  6.             android:layout_width="match_parent"
  7.             android:layout_height="100dp"
  8.             android:background="#FFFF00" />
  9.     <TextView
  10.             android:layout_width="match_parent"
  11.             android:layout_height="wrap_content"
  12.             android:gravity="center"
  13.             android:background="@android:color/black"
  14.             android:text="@string/hello_world"
  15.             android:padding="50dp" />
  16.     <View
  17.             android:layout_width="match_parent"
  18.             android:layout_height="match_parent"
  19.             android:background="#FF0000" />         
  20. </LinearLayout>
复制代码
而这也正是它看起来在设备上运行时。

哇,你设置了红色的View到MATCH_PARENT ,它填补了剩余空间LinearLayout 。 这是不一样大是其父母。 怎么办?
而这里的混乱。 LinearLayout将其子顺序,一个孩子的起始位置是以前的孩子的结束位置。 一个孩子请求父母给它一定的尺寸,但是这并不影响在孩子的位置。
由于红色视图是第三,它是奠定了前两个之后,因此,最终不作为“大如父。”
这是一个后果不如何的位置, MATCH_PARENT /FILL_PARENT工作。 在LinearLayout信守孩子的请求意见,最好是可以的,但不能保证他们。

现在,让我们看看当我们切换事情使红色周围发生什么事View第一个布局:
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.               android:layout_width="match_parent"
  3.               android:layout_height="match_parent"
  4.               android:orientation="vertical">    
  5.     <View
  6.             android:layout_width="match_parent"
  7.             android:layout_height="match_parent"
  8.             android:background="#FF0000" />
  9.     <View
  10.             android:layout_width="match_parent"
  11.             android:layout_height="100dp"
  12.             android:background="#FFFF00" />
  13.     <TextView
  14.             android:layout_width="match_parent"
  15.             android:layout_height="wrap_content"
  16.             android:gravity="center"
  17.             android:background="@android:color/black"
  18.             android:text="@string/hello_world"
  19.             android:padding="50dp" />             
  20. </LinearLayout>
复制代码

现在,这里是什么样子,而且很容易看出差别。 由于LinearLayout勾画出红色景观第一,它是定位在顶部,可以充分满足其MATCH_PARENT请求。 这导致了红色View推动其他两个淡出人们的视线。

好吧,如果我真的想做出一个View填写其父的剩余空间?

-----------------------------------------------------------------------------------------------------------------------------------
如何真正“补母”
实施“补母”的总体战略是使用LinearLayout和layout_weight属性。 现在我们将用它们来解决我们认为被接管的斑点(即红二布局View )。
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.               android:layout_width="match_parent"
  3.               android:layout_height="match_parent"
  4.               android:orientation="vertical">             
  5.     <View
  6.             android:layout_width="match_parent"
  7.             android:layout_height="0dp"
  8.             android:layout_weight="1"
  9.             android:background="#FF0000" />
  10.     <View
  11.             android:layout_width="match_parent"
  12.             android:layout_height="100dp"
  13.             android:background="#FFFF00" />
  14.     <TextView
  15.             android:layout_width="match_parent"
  16.             android:layout_height="wrap_content"
  17.             android:gravity="center"
  18.             android:background="@android:color/black"
  19.             android:text="@string/hello_world"
  20.             android:padding="50dp" />
  21. </LinearLayout>
复制代码

在这里,我们能够保持红View的第一个孩子在LinearLayout ,并让它只铺设了另外两个意见后填写剩余的空间。

真的有永远只是一种方式来创建一个布局。如果我们想只是让红色View最后在LinearLayout ,并让它填补剩余的空间,我们可以使用故事的第一个布局,
结束。 但是,必须明白为什么它的工作原理,当它可能无法正常工作是非常重要的。

原文:http://randomlytyping.com/blog/2014/2/9/matchparent-vs-fillparent  这是翻译的文章
做什么

match_parent_vs_fill_parent_layout_01.png (13.54 KB, 下载次数: 3)

match_parent_vs_fill_parent_layout_01.png

match_parent_vs_fill_parent_layout_02.png (4.56 KB, 下载次数: 3)

match_parent_vs_fill_parent_layout_02.png

match_parent_vs_fill_parent_layout_03.png (13.41 KB, 下载次数: 6)

match_parent_vs_fill_parent_layout_03.png
http://www.xdnf.cn/news/11712.html

相关文章:

  • Android 系统升级流程分析
  • 0-1背包问题(回溯法c++详解)
  • STM32外部挂载SDcard+移植Fatfs文件系统
  • tl r402路由器设置_tplogin.cn登录路由器怎么设置 tplogin.cn登录路由器设置步骤【详解】...
  • Android光线传感器获取光线强弱。LightSensorManager封装类
  • position的relative与absolute的区别
  • 非线性丙类功率放大器实验_倾斜光纤Bragg光栅:抑制高功率光纤激光系统SRS和SBS的理想选择...
  • 网安学习日志01:用kali复现ms17-010漏洞
  • 传奇私服游戏支付接口申请(已解决)
  • iTunes 9.0.3 更新
  • Linux系统服务之inetd
  • 445端口入侵详解
  • 用 Java 实现“人像动漫化”特效
  • Windows 安全基础——NetBIOS篇
  • 硬盘模式JBOD
  • C++实现银行家算法
  • 应用程序发生异常--未知的软件异常怎么办?
  • 【Android动画入门篇】
  • 寄存器分配图着色_着色基础------抗锯齿与半透明
  • Adobe Acrobat pro 9.0 序列号
  • 【硬核】优质 嵌入式C编程 必备指南
  • 张老师的生日究竟是哪天(经典推理题[转载])
  • php core,分析php core dump的原因
  • Unity3D入门基础知识汇总
  • 在线免费生成IntelliJ IDEA 15.0(16.+)注册码
  • tab切换之图片切换
  • a标签点击中文文件名乱码,通过a标签href属性跳转后台乱码问题
  • 电子合同签署平台有哪些?2024年靠谱10家对比
  • 深入剖析《开端》是如何找到引爆凶手的?
  • 802.11n无线网卡驱动linux,安装Broadcom Linux hybrid 无线网卡驱动总结