[英]What is it that android:layout_width and layout_height refer to? Does it include the margin?
It seems that the the Android layout_width and layout_height only includes the content and the padding of the view. 似乎Android的layout_width和layout_height仅包含视图的内容和填充。 If so, why does the following code work? 如果是这样,以下代码为何起作用?
I have read this post , however, although I understand what needed to be done in that case, I don't understand why it works. 我已经阅读了这篇文章 ,但是,尽管我知道在这种情况下需要做些什么,但我不明白它为什么起作用。
I am using RecyclerView, with similar code to the linked example. 我正在使用RecyclerView,其代码与链接的示例相似。 Each item of the RecyclerView is a CardView 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>
And for my code 而对于我的代码
@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 and layout_height in card view is the size of this card view. 卡视图中的layout_width和layout_height是此卡视图的大小。 I think you fit this card view in its parent view. 我认为您适合此卡片视图的父视图。 Whatever if you use "match_parent" in child view, your child view will fill its parent view and it will not fill the screen. 无论您在子视图中使用“ match_parent”如何,子视图都将填充其父视图,而不会填充屏幕。 So, you should check parent view of this card view. 因此,您应该检查此卡片视图的父视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.