如何防止CardView cardElevation更改API 19上的内容大小?

问题描述 投票:0回答:1

这是我的xml文件:

<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,右侧是Android 8,api26。您可以看到,API 19的结果将截断图像。如何使左侧的图像看起来与右侧的图像相同。?

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

android cardview android-elevation
1个回答
0
投票

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

ImageView属性中删除此属性:android:scaleType="centerCrop",然后在cardView中将高度设置为wrap_content android:layout_height="wrap_content"

© www.soinside.com 2019 - 2024. All rights reserved.