【问题标题】:Card View with round corner API 27圆角卡片视图 API 27
【发布时间】:2021-12-28 15:23:30
【问题描述】:

下面是我的代码:

<androidx.cardview.widget.CardView
    android:layout_width="78dp"
    android:layout_height="78dp"
    android:layout_gravity="center"
    app:cardBackgroundColor="?colorSecondary"
    app:cardCornerRadius="250dp">

    <ImageView
        android:id="@+id/customer_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/content_description"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_no_picture" />

</androidx.cardview.widget.CardView>

它与 API 30/29/28 完美配合,但对于 API 27,我只有一个空的 CardView。你有什么想法吗?

【问题讨论】:

  • 给 app:cardBackgroundColor 显式颜色怎么样?
  • 感谢您的提示,但我已经尝试过使用明确的颜色

标签: android xml android-cardview


【解决方案1】:

github上有很多库可以将Imageview做成圆形。可以去github探索一下。

Here is the one of its's kind for CircularImageView

【讨论】:

  • 我不想使用库,这只是一个简单的事情的技术债务
【解决方案2】:

我刚刚找到了一种方法来解决我的问题,使用 API 27 来获得带有 cardView 的圆形图像,您必须将 cardCornerRadius 设置为最大宽度/高度。 在我的示例中,我只写了app:cardCornerRadius="39dp",它运行良好。

【讨论】:

    猜你喜欢
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2013-06-24
    • 2021-03-23
    • 2017-11-14
    • 2021-10-24
    相关资源
    最近更新 更多