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

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

我正在尝试将 StaggeredGridLayoutManagerandroid.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.x.x 上图像不会调整大小以填充项目的宽度/高度(因为有一个比例类型 centerInside 不适合该商品的尺寸)。 我现在无法在真正的 4.x.x 设备上尝试它,有谁知道这是否仅在模拟器或什至在某些真正的 4.x.x 设备中是个问题?

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

If the application targets API level 17 or lower, adjustViewBounds will allow the drawable to shrink the view bounds, but not grow to fill available measured space in all cases.

最佳答案

此问题仅与 android:adjustViewBounds="true" 的行为有关,这似乎从 Android 4.3 开始能够在 ImageView 中缩放图像,而不仅仅是向下调整原生尺寸但也向上保持比例。

关于android - 带有 CardView 的 StaggeredGridLayoutManager 不适合项目测量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29622344/

相关文章:

android - 带有浅色应用程序主题的深色工具栏

android - 检测音频信号中的频率变化点

java - Android:仅从父 Activity 调用子 Activity 的函数

java - @AndroidEntryPoint 基类必须扩展 ComponentActivity,(支持)Fragment、View、Service 或 BroadcastReceiver

android - 如何在 <TabHost> 标签内显示文本?安卓

Android Lollipop 模拟器 Nexus S 未运行该应用程序

android - 如何设置适合任何屏幕高度的布局?

java - 使用 Google Maps Android 标记聚类实用程序时无法实例化 appComponentFactory

java.lang.UnsupportedOperationException : Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f010046 a=-1} 异常

android - 如何以编程方式在 Android(KitKat 及更高版本)中添加 APN