不推荐使用的单词是 fill_father 和 match_father 之间的唯一区别

我发现 fill_parentmatch_parent的意思是一样的

  • Fill _ father 意味着视图希望与其父视图一样大,但是减去父视图的填充(如果有的话)。
  • Match _ father 意味着视图希望与其父视图一样大,减去父视图的填充(如果有的话)。

我发现的唯一不同之处是,从 API 级别8开始就不推荐使用 fill_parent,而代之以 match_parent

然而,我没有注意到这两者之间有什么不同。如果两者是相同的,那么为什么 fill_parent会被弃用。有人能解释一下这两者之间的区别吗,除了一个被否定了,另一个没有?

我已经通过 http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

34243 次浏览

我在 Android 上开发了足够长的时间,也意识到似乎没有什么区别,除非你想在一个旧的 API 上运行。我会使用 fill_parent,因为我的所有应用程序的最低 API 7。此外,顺便说一句,因为 Android 是向前兼容的,所以这才是正确的做法。

根据 这个视频中的罗曼 · 盖伊,这些词表明了同样的行为。但是许多开发人员误解了 fill _ father 的意思,因此他们提出了一个别名。

就像你说的一模一样。正如 RomainGuy 所说,他们更改了名称,因为 "fill_parent"让开发人员感到困惑。事实上,"fill_parent"不会填充剩余的空间(因为您使用 weight 属性) ,但是它占用的空间与其布局父元素一样多。这就是为什么新名字是 "match_parent"

现有答案的补充。下面是来自 LayoutParams类的源代码的一部分,FILL _ PARENT 和 MATCH _ PARENT 常量都映射到相同的值。所以我们有完全相同的功能。

    public static class LayoutParams {
/**
* Special value for the height or width requested by a View.
* FILL_PARENT means that the view wants to be as big as its parent,
* minus the parent's padding, if any. This value is deprecated
* starting in API Level 8 and replaced by {@link #MATCH_PARENT}.
*/
@SuppressWarnings({"UnusedDeclaration"})
@Deprecated
public static final int FILL_PARENT = -1;


/**
* Special value for the height or width requested by a View.
* MATCH_PARENT means that the view wants to be as big as its parent,
* minus the parent's padding, if any. Introduced in API Level 8.
*/
public static final int MATCH_PARENT = -1;
...