看来,在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'通常是指内容+填充,而不是利润率。保证金被视为不在视野范围之内。 –