看來,在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'通常是指內容+填充,而不是利潤率。保證金被視爲不在視野範圍之內。 –