android fill_parentとmatch_parentの違い
14014 ワード
3つのプロパティは、ビューの水平または垂直のサイズに適応するために使用され、ビューの内容またはサイズに基づいたレイアウトは、ビューの範囲を正確に指定するよりも便利です.
1)fill_parent
コンポーネントのレイアウトをfill_に設定parentは、レイアウトユニット内の可能な限り多くの空間を満たすためにコンポーネントを強制的に拡張する.これはWindowsコントロールのdockstyleプロパティとほぼ一致します.上部レイアウトまたはコントロールをfill_に設定parentは強制的に画面全体を埋め尽くします.
2) wrap_content
ビューのサイズをwrap_に設定contentは、ビューを強制的に拡張してすべてのコンテンツを表示します.TextViewとImageViewコントロールを例にwrap_に設定contentは内部のテキストと画像を完全に表示します.レイアウト要素は、コンテンツに応じてサイズが変更されます.ビューのサイズをwrap_に設定contentは、WindowsコントロールのAutosizeプロパティをTrueに設定するのとほぼ同じです.
3)match_parent Android2.2-2 match_parentとfill_parentとはどういう意味ですか.2つのパラメータは同じ意味ですmatch_parentはもっと適切で、2.2から2つの言葉が使えます.では、低バージョンの使用状況を考慮するとfill_を使う必要があります.parentだ
android.view.ViewGroup.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;
/** * Special value for the height or width requested by a View. * WRAP_CONTENT means that the view wants to be just large enough to fit * its own internal content, taking its own padding into account. */public static final int WRAP_CONTENT = -2;
1)fill_parent
コンポーネントのレイアウトをfill_に設定parentは、レイアウトユニット内の可能な限り多くの空間を満たすためにコンポーネントを強制的に拡張する.これはWindowsコントロールのdockstyleプロパティとほぼ一致します.上部レイアウトまたはコントロールをfill_に設定parentは強制的に画面全体を埋め尽くします.
2) wrap_content
ビューのサイズをwrap_に設定contentは、ビューを強制的に拡張してすべてのコンテンツを表示します.TextViewとImageViewコントロールを例にwrap_に設定contentは内部のテキストと画像を完全に表示します.レイアウト要素は、コンテンツに応じてサイズが変更されます.ビューのサイズをwrap_に設定contentは、WindowsコントロールのAutosizeプロパティをTrueに設定するのとほぼ同じです.
3)match_parent Android2.2-2 match_parentとfill_parentとはどういう意味ですか.2つのパラメータは同じ意味ですmatch_parentはもっと適切で、2.2から2つの言葉が使えます.では、低バージョンの使用状況を考慮するとfill_を使う必要があります.parentだ
android.view.ViewGroup.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;
/** * Special value for the height or width requested by a View. * WRAP_CONTENT means that the view wants to be just large enough to fit * its own internal content, taking its own padding into account. */public static final int WRAP_CONTENT = -2;
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;
/**
* Special value for the height or width requested by a View.
* WRAP_CONTENT means that the view wants to be just large enough to fit
* its own internal content, taking its own padding into account.
*/
public static final int WRAP_CONTENT = -2;
/**
* Information about how wide the view wants to be. Can be one of the
* constants FILL_PARENT (replaced by MATCH_PARENT ,
* in API Level 8) or WRAP_CONTENT. or an exact size.
*/
@ViewDebug.ExportedProperty(category = "layout", mapping = {
@ViewDebug.IntToString(from = MATCH_PARENT, to = "MATCH_PARENT"),
@ViewDebug.IntToString(from = WRAP_CONTENT, to = "WRAP_CONTENT")
})
public int width;
/**
* Information about how tall the view wants to be. Can be one of the
* constants FILL_PARENT (replaced by MATCH_PARENT ,
* in API Level 8) or WRAP_CONTENT. or an exact size.
*/
@ViewDebug.ExportedProperty(category = "layout", mapping = {
@ViewDebug.IntToString(from = MATCH_PARENT, to = "MATCH_PARENT"),
@ViewDebug.IntToString(from = WRAP_CONTENT, to = "WRAP_CONTENT")
})
public int height;
/**
* Used to animate layouts.
*/
public LayoutAnimationController.AnimationParameters layoutAnimationParameters;
/**
* Creates a new set of layout parameters. The values are extracted from
* the supplied attributes set and context. The XML attributes mapped
* to this set of layout parameters are:
*
*
* layout_width
: the width, either an exact value,
* {
@link #WRAP_CONTENT}, or {@link #FILL_PARENT} (replaced by
* {@link #MATCH_PARENT} in API Level 8)
* layout_height
: the height, either an exact value,
* { @link #WRAP_CONTENT}, or {@link #FILL_PARENT} (replaced by
* {@link #MATCH_PARENT} in API Level 8)
*
*
* @param c the application environment
* @param attrs the set of attributes from which to extract the layout
* parameters' values
*/
public LayoutParams(Context c, AttributeSet attrs) {
TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.ViewGroup_Layout);
setBaseAttributes(a,
R.styleable.ViewGroup_Layout_layout_width,
R.styleable.ViewGroup_Layout_layout_height);
a.recycle();
}
/**
* Creates a new set of layout parameters with the specified width
* and height.
*
* @param width the width, either {@link #WRAP_CONTENT},
* {@link #FILL_PARENT} (replaced by {@link #MATCH_PARENT} in
* API Level 8), or a fixed size in pixels
* @param height the height, either {@link #WRAP_CONTENT},
* {@link #FILL_PARENT} (replaced by {@link #MATCH_PARENT} in
* API Level 8), or a fixed size in pixels
*/
public LayoutParams(int width, int height) {
this.width = width;
this.height = height;
}
/**
* Copy constructor. Clones the width and height values of the source.
*
* @param source The layout params to copy from.
*/
public LayoutParams(LayoutParams source) {
this.width = source.width;
this.height = source.height;
}
/**
* Used internally by MarginLayoutParams.
* @hide
*/
LayoutParams() {
}
/**
* Extracts the layout parameters from the supplied attributes.
*
* @param a the style attributes to extract the parameters from
* @param widthAttr the identifier of the width attribute
* @param heightAttr the identifier of the height attribute
*/
protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) {
width = a.getLayoutDimension(widthAttr, "layout_width");
height = a.getLayoutDimension(heightAttr, "layout_height");
}
/**
* Returns a String representation of this set of layout parameters.
*
* @param output the String to prepend to the internal representation
* @return a String with the following format: output +
* "ViewGroup.LayoutParams={ width=WIDTH, height=HEIGHT }"
*
* @hide
*/
public String debug(String output) {
return output + "ViewGroup.LayoutParams={ width="
+ sizeToString(width) + ", height=" + sizeToString(height) + " }";
}
/**
* Converts the specified size to a readable String.
*
* @param size the size to convert
* @return a String instance representing the supplied size
*
* @hide
*/
protected static String sizeToString(int size) {
if (size == WRAP_CONTENT) {
return "wrap-content";
}
if (size == MATCH_PARENT) {
return "match-parent";
}
return String.valueOf(size);
}
}