似乎Android 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;
}
答案 0 :(得分:-1)