Androidのfill_parentとmatch_parentの違い



Difference Between Fill_parent



Androidのfill_parentとmatch_parentの違い

今日デモをダウンロードしたとき、その中のレイアウトはすべてfill_parentを使用していることがわかりましたが、以前は常にmatch_parentを使用していました。私の友人のほとんどは開発時にmatch_parentを使用するはずですが、それらの違いは何ですか?この質問で、私はAndroidのソースコードを読みに行きました。私はそれらがただ一つのものであることを知りました。次に、情報を調べたところ、Android 2.2以降、Androidはマッピングによってすべてのfill_parentをmatch_parentに変更しましたが、Android 2.2より前では、match_parentメソッドがありませんでした。ので それは実際には物です
ソースコードでのそれらの関係は次のとおりです。

public static int getChildMeasureSpec(int spec, int padding, int childDimension) { ... //According to the currently selected Mode to do the corresponding processing switch (specMode) { case MeasureSpec.EXACTLY: //If childDimension = wrap_content. The size gives the measured size, and the mode is set to AT_MOST. //Acquire the MeasureSpec corresponding to the child view according to childDimension. if (childDimension >= 0) { //There are specific values, and the layout is specific to specific values. resultSize = childDimension resultMode = MeasureSpec.EXACTLY } else if (childDimension == LayoutParams.MATCH_PARENT) { // match_parent, assign the size of the parent control to the child view, and set the mode to the exact size EXACTLY. resultSize = size resultMode = MeasureSpec.EXACTLY } else if (childDimension == LayoutParams.WRAP_CONTENT) { // wrap_content, then the value of the parent control is assigned to the child control, the mode is set to AT_MOST, and the maximum value cannot exceed this setting. resultSize = size resultMode = MeasureSpec.AT_MOST } break case MeasureSpec.AT_MOST: ... break ... } //Return the value of MeasureSpec (including resultSize and resultMode) measured above. return MeasureSpec.makeMeasureSpec(resultSize, resultMode) }

ご覧のとおり、ソースコードにはmatch_parentとwrap_contentの2つのケースしかなく、これら2つのケースのみが処理され、fill_parentが見つかりません。実際、android2.2以降、fill_parentはmatch_panrentに名前が変更されました。したがって、それらの効果は同じです。
最後にSDKに説明を投稿しました:
(1)fill_parent -1ビューは、その親と同じ大きさである必要があります(パディングを除く)。この定数はAPIレベル8から非推奨になり、match_parentに置き換えられました。
(2)match_parent -1ビューは、その親と同じ大きさである必要があります(パディングを除く)。 APIレベル8で導入されました。
(3)wrap_content -2ビューは、コンテンツ(およびパディング)を囲むのに十分な大きさである必要があります。