【问题标题】:How to prevent CardView cardElevation changing the content size on API 19?如何防止 CardView cardElevation 更改 API 19 上的内容大小?
【发布时间】:2020-01-28 05:49:57
【问题描述】:

ConstraintLayout 中带有 CardView 的布局文件:

<androidx.cardview.widget.CardView
        android:id="@+id/cardview"
        android:layout_width="392dp"
        android:layout_height="0dp"
        app:cardElevation="32dp"
        app:cardBackgroundColor="#000000"
        app:layout_constraintDimensionRatio="H,16:9"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/eagle"
            tools:ignore="contentDescription"/>

</androidx.cardview.widget.CardView>

这是结果,左侧是 Android 4.4.2,API 19 V.S. Android 8 上的右侧,api 26。如您所见,API 19 上的结果是截断图像。 是否要防止 CardView 的属性 cardElevation 切入 API 19 或更早版本的内容?

这是用于测试的图片网址: http://t.wallpaperweb.org/wallpaper/animals/1920x1080/Bald_Eagle_in_Flight_Alaska.jpg

【问题讨论】:

    标签: android cardview android-elevation


    【解决方案1】:

    我认为这与api 级别无关,它与屏幕尺寸/密度有关。

    删除此表单您的ImageView 属性:android:scaleType="centerCrop" 并在您的cardView 中将高度设置为wrap_content android:layout_height="wrap_content"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-02
      • 2021-08-21
      • 2014-09-11
      • 1970-01-01
      • 2011-10-16
      • 1970-01-01
      • 2021-06-24
      • 2011-03-17
      相关资源
      最近更新 更多