Android layout_widthとlayout_heightには、コンテンツの内容とビューのパディングだけが含まれているようです。その場合、次のコードはなぜ機能しますか?アンドロイド:layout_widthとlayout_heightはどういう意味ですか?マージンを含んでいますか?
私はthis postと読みましたが、その場合に何が必要かを理解していますが、なぜそれが機能するのか分かりません。
私はRecyclerViewを使用していますが、リンクされた例と同様のコードです。 RecyclerViewの各項目は、CardView
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent "
android:layout_height="200dp"
card_view:cardCornerRadius="4dp"
android:padding="40dp"
android:layout_margin="24dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.CardContent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/my_text_view"
android:text="fub"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lorem ipsum dolor sit amet"/>
</LinearLayout>
そして、私のコードのためのカードビューで
@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row_view, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
あなたの特定のレイアウトの質問についてはわかりませんが、 'layout_width'と' layout_height'は通常content + paddingを参照しますが、マージンは参照しません。マージンはビューの外側と見なされます。 –