带有CardView的StaggeredGridLayoutManager不适合项目测量

时间:2015-04-14 08:17:24

标签: android android-emulator android-appcompat android-recyclerview staggeredgridlayout

我正在尝试将 StaggeredGridLayoutManager android.support.v7.widget(v22)中的 CardView 一起使用。 这是我的项目布局:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    card_view:cardUseCompatPadding="true"
    card_view:cardCornerRadius="6dp"      >

    <RelativeLayout
        android:id="@+id/layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="5dip" >

    <ImageView
        android:id="@+id/photo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:adjustViewBounds="true" />

    </RelativeLayout> 

</android.support.v7.widget.CardView>

在模拟器和5.0+设备上,它可以正常运行,但在模拟器4.xx上,图像不会调整大小以填充项目的宽度/高度(因为有类似缩放类型 centerInside 不符合项目的衡量标准)。 我现在无法在真正的4.x.x设备上尝试它,有人知道它是仅在模拟器中还是在一些真正的4.x.x设备中出现问题?

解决 来自文档http://developer.android.com/reference/android/widget/ImageView.html#setAdjustViewBounds(boolean)] 1

  

如果应用程序的目标是API级别17或更低,请调整ViewBounds   将允许drawable缩小视图边界,但不会增长到   在所有情况下填充可用的测量空间。

2 个答案:

答案 0 :(得分:2)

此问题仅与android:adjustViewBounds="true"的行为有关,似乎从Android 4.3能够在ImageView中缩放图像,不仅可以向下调整本机尺寸,还可以向上保持比例。

答案 1 :(得分:0)

虽然很晚但我相信这应该是批准的答案。我们必须创建自己的ImageView并根据可用的固定高度/宽度测量备用尺寸。 @Nuuneoi已尽力将其付诸行动。请关注此Github link

相关问题