简体   繁体   English

android:layout_width和layout_height指的是什么? 它包括保证金吗?

[英]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;
}

screenshot here 屏幕截图在这里

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.

相关问题 将 <include> 覆盖layout_width / layout_height值? - Will <include> override the layout_width/layout_height value? Android 数据绑定 layout_width 和 layout_height - Android Data Binding layout_width and layout_height 为什么setImageBitmap会覆盖layout_height和layout_width? - Why does setImageBitmap override layout_height and layout_width? Android Studio XML 需要 Layout_Height 和 Layout_Width - Android Studio XML Requires Layout_Height and Layout_Width 如何在Android中自动layout_width / layout_height? - How to auto layout_width / layout_height in android? Android layout_width&layout_height,它是如何工作的? - Android layout_width & layout_height, how it works? android:scaleType =“fitCenter”只能用于修复Layout_width和Layout_height属性吗? - Does android:scaleType=“fitCenter” only work with fix Layout_width and Layout_height attributes? Android 布局文件中的所有小部件都需要 layout_width 和 layout_height 吗? - Do all widgets in an Android layout file require layout_width and layout_height? Android获得了夸大的布局layout_width和layout_height值 - Android get inflated layout layout_width and layout_height values 未知属性 android:layout_width、layout_height、id、gravity、layout_gravity、padding - Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity, padding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM