0

看来,在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; 
} 

screenshot here

+0

不确定您的特定布局的问题,但'layout_width'和'layout_height'通常是指内容+填充,而不是利润率。保证金被视为不在视野范围之内。 –

回答

-1

layout_width和layout_height卡的看法是这样的卡片视图的大小。我认为你在其父视图中适合这张卡片视图。无论你在子视图中使用“match_parent”,你的子视图将填充它的父视图,并且它不会填满屏幕。所以,你应该检查这张卡片视图的父视图。

+1

这不回答我的问题。什么是“大小”?填充和内容?或填充,内容和边距? –

+0

大小是您的视图的宽度和高度。 layout_width是它的宽度,它不能超过它的父视图。所以,如果你在你的子视图中使用填充,它会影响到它的父视图。 – Zayar

相关问题