【问题标题】:Is deprecated word the only difference between fill_parent and match_parent不推荐使用的单词是fill_parent和match_parent之间的唯一区别
【发布时间】:2012-01-20 22:56:55
【问题描述】:

我发现fill_parentmatch_parent 的意思是一样的

  • fill_parent 表示视图希望与其父级一样大,减去父级的填充(如果有)。
  • ma​​tch_parent 表示视图希望与其父级一样大,减去父级的填充(如果有)。

我发现的唯一区别是 fill_parent 从 API 级别 8 开始已被弃用,并被 match_parent 取代

但是,我没有注意到这两者之间有任何区别。如果两者相同,那么为什么不推荐使用fill_parent。谁能解释这两者之间的任何区别,除了一个已弃用而另一个未弃用这一事实吗?

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

【问题讨论】:

标签: android


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    根据this 视频中的 Romain Guy 所说,这些词标志着相同的行为。但是很多开发者误解了 fill_parent 的意思,所以他们想出了一个别名。

    【讨论】:

      【解决方案3】:

      我已经在 Android 中开发了足够长的时间,也意识到似乎没有什么区别,除非您想在较旧的 API 上运行。我会使用fill_parent,因为我使用最低 API 7 制作我的所有应用程序。另外,顺便说一下,由于 Android 是向前兼容的,这是要走的路。

      【讨论】:

        【解决方案4】:

        对现有答案的补充。这是来自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;
            ...
        

        【讨论】:

          猜你喜欢
          • 2012-06-29
          • 2011-08-11
          • 2013-04-02
          • 2013-04-04
          • 1970-01-01
          • 2017-12-06
          • 2012-04-14
          • 1970-01-01
          • 2011-10-25
          相关资源
          最近更新 更多