使用 fill_parent 仍然是正确的做法吗?
Is using fill_parent still a proper practice?
在研究 match_parent
和 fill_parent
之间的区别时,我 found 在 API 8 时期 Google 只是 'renamed' fill_parent
到 match_parent
因为后者更好地描述了效果并使 fill_parent
被弃用。
对我来说很愚蠢,官方和可靠 IDE 至少在代码检查部分,经过这么多年 Android Studio 2.3.3 仍然没有突出显示 [=12] 的用法=] 已弃用并且不要求将其更改为 match_parent
。它也没有在建议列表中删除 fill_parent
。
所以问题是我们应该在新代码中始终使用 match_parent
而不是 fill_parent
还是交替使用它们是 Android 开发中的一种既定做法,这就是为什么Android Studio 不会警告我们弃用 fill_parent
?
https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT
在文档中,您可以看到 FILL_PARENT 和 MATCH_PARENT 具有相同的值 (-1),所以它们只是名称不同而已。
在这个 post http://www.randomlytyping.com/blog/2014/2/9/matchparent-vs-fillparent 中,它的解释很像:
So why was MATCH_PARENT added?
The Android team found that developers were misinterpreting FILL_PARENT to mean that a View would fill the remaining space left in its parent. In fact, by specifying FILL_PARENT, the View is requesting to be as big as its parent.
Okay, I get how FILL_PARENT/MATCH_PARENT works. What does it matter if I use one or the other?
FILL_PARENT is deprecated. Being deprecated does not make it the Devil, but eventually it will go away. Your application is more future-proof using MATCH_PARENT. Why use the deprecated option when the current option behaves exactly the same?
在研究 match_parent
和 fill_parent
之间的区别时,我 found 在 API 8 时期 Google 只是 'renamed' fill_parent
到 match_parent
因为后者更好地描述了效果并使 fill_parent
被弃用。
对我来说很愚蠢,官方和可靠 IDE 至少在代码检查部分,经过这么多年 Android Studio 2.3.3 仍然没有突出显示 [=12] 的用法=] 已弃用并且不要求将其更改为 match_parent
。它也没有在建议列表中删除 fill_parent
。
所以问题是我们应该在新代码中始终使用 match_parent
而不是 fill_parent
还是交替使用它们是 Android 开发中的一种既定做法,这就是为什么Android Studio 不会警告我们弃用 fill_parent
?
https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT
在文档中,您可以看到 FILL_PARENT 和 MATCH_PARENT 具有相同的值 (-1),所以它们只是名称不同而已。
在这个 post http://www.randomlytyping.com/blog/2014/2/9/matchparent-vs-fillparent 中,它的解释很像:
So why was MATCH_PARENT added?
The Android team found that developers were misinterpreting FILL_PARENT to mean that a View would fill the remaining space left in its parent. In fact, by specifying FILL_PARENT, the View is requesting to be as big as its parent.
Okay, I get how FILL_PARENT/MATCH_PARENT works. What does it matter if I use one or the other?
FILL_PARENT is deprecated. Being deprecated does not make it the Devil, but eventually it will go away. Your application is more future-proof using MATCH_PARENT. Why use the deprecated option when the current option behaves exactly the same?