我想实现一个2x2的GridLayout,这样我就可以显示4个卡片视图。我的问题是单一的卡片视图占据了所有的空间。当我添加第二个(第0行,第1列)时,它位于屏幕之外(在右侧)。
这是我的布局代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.gridlayout.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rowCount="2">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_row="0"
app:layout_column="0" />
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_row="0"
app:layout_column="1" />
</androidx.gridlayout.widget.GridLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
发布于 2021-01-17 20:48:49
两个CardViews都与父对象的宽度匹配,这就是为什么您只看到一个,您可以像这样更改它
android:layout_width="wrap_content"
app:layout_columnWeight="1"
使用app:layout_columnWeight
将确保两张卡具有相同的宽度,而不管其内容如何
发布于 2021-01-17 20:37:25
使用两个cardview的layout_width
作为wrap_content
https://stackoverflow.com/questions/65760504
复制相似问题