fill_parentAndroid でウィジェットをレイアウトするとき、 ( match_parentAPI レベル 8 以降) との違いは何wrap_contentですか?
参照できるドキュメントはありますか? 私はそれを非常によく理解することに興味があります。
fill_parentAndroid でウィジェットをレイアウトするとき、 ( match_parentAPI レベル 8 以降) との違いは何wrap_contentですか?
参照できるドキュメントはありますか? 私はそれを非常によく理解することに興味があります。
fill_parent(非推奨) =match_parent
子ビューの境界線は、親ビューの境界線と一致するように拡張されます。
wrap_content
子ビューの境界線は、それ自体のコンテンツをぴったりと包み込みます。
物事をより明確にするために、いくつかの画像を次に示します。緑と赤はTextViews. 白はLinearLayout透け透けです。

すべてViewの (a TextView、 an ImageView、 aButtonなど) は、ビューのwidthおよびを設定する必要heightがあります。xml レイアウト ファイルでは、次のようになります。
android:layout_width="wrap_content"
android:layout_height="match_parent"
幅と高さをmatch_parentまたはwrap_contentに設定する以外に、絶対値に設定することもできます。
android:layout_width="100dp"
android:layout_height="200dp"
ただし、さまざまなサイズのデバイスに柔軟に対応できないため、一般的にはそれほど良くありません。と を理解wrap_contentしたらmatch_parent、次に学ぶのはlayout_weightです。
垂直 LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="width=wrap height=wrap"
android:background="#c5e1b0"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="width=match height=wrap"
android:background="#f6c0c0"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="width=match height=match"
android:background="#c5e1b0"/>
</LinearLayout>
水平 LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="WrapWrap"
android:background="#c5e1b0"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="WrapMatch"
android:background="#f6c0c0"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MatchMatch"
android:background="#c5e1b0"/>
</LinearLayout>
この回答の説明では、マージンやパディングがないことを前提としています。しかし、あっても基本的なコンセプトは同じです。ビューの境界線/間隔は、マージンまたはパディングの値によって調整されます。
fill_parent要素の幅または高さを親要素、つまりコンテナと同じ大きさにします。
wrap_contentその中に要素を含めるのに必要なだけ幅または高さを大きくします。
fill_parent:
コンポーネントを配置するレイアウトはfill_parent、レイアウト ユニット メンバーをできるだけスペースに収まるように拡張する必要があります。これは、Windows コントロールの Dockstyle プロパティと一致しています。トップセットのレイアウトまたはコントロールfill_parentは、強制的に画面全体を占有します。
wrap_content
のサイズのビューを設定すると、wrap_contentすべてのコンテンツが表示されるように強制的に展開されます。たとえば、TextView コントロールと ImageView コントロールは、内部テキストとイメージ全体を表示するように設定されていますwrap_content。レイアウト要素は、コンテンツに応じてサイズが変わります。wrap_contentWindows コントロールを True に設定するのとほぼ同じAutosize 属性のサイズのビューを設定します。
詳細については、このリンクを確認してください: http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html