0
出于某种原因,我的CardView仅在网格视图中显示第一行图像。 (或者我的GridView只显示第一行 - 我看不出来)。CardView仅显示GridLayout的第一行
我动态地将图像添加到gridView中,并使用gridAdapter.notifyDataSetChanged()
。也许这就是为什么CardView的高度不适应?当我向CardView添加android:layout_height =“500dp”时,我会看到所有图像。
有没有办法让CardView包装内容,以便我可以看到我的所有图像(除了硬编码高度)?
请注意,由于照片的行数是动态的,我无法对高度进行硬编码。
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/m_photos" />
<GridView
android:id="@+id/m_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:clickable="true"
android:columnWidth="90dp"
android:drawSelectorOnTop="true"
android:focusable="true"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="none"
android:verticalSpacing="2dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
如果存在多行照片,则此功能起作用。但是,照片的数量是动态的,并且当只有一行照片时,我不想显示多行。 – Vinnie