【发布时间】:2018-08-17 16:42:21
【问题描述】:
我尝试在 Android 应用程序中使用带有角半径的 ImageView 创建 CardView。
我发现当我们尝试将 cardCornerRadius 设置为超过 0 时,例如 12dp,它没有将半径应用于 CardView 内部的 ImageView。
如何将半径应用于 CardView 内的 ImageView? 提前感谢您的帮助。
created image with app:cardCornerRadius="0dp"
created image with app:cardCornerRadius="12dp"
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="@dimen/card_height"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/md_keylines"
android:layout_marginLeft="@dimen/md_keylines"
android:layout_marginRight="@dimen/md_keylines"
app:cardCornerRadius="12dp" // This radius is not applied to the ImageView with @id/card_image
android:foreground="?attr/selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/card_image"
android:layout_width="match_parent"
android:layout_height="@dimen/card_image_height"
android:scaleType="centerCrop"
tools:src="@drawable/a" />
<TextView
android:id="@+id/card_title"
android:layout_width="match_parent"
android:layout_height="@dimen/card_title_height"
android:layout_alignBottom="@+id/card_image"
android:layout_marginLeft="@dimen/md_keylines"
tools:text="@string/item_title"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="@color/white" />
<TextView
android:id="@+id/card_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/card_image"
android:layout_marginLeft="@dimen/md_keylines"
android:layout_marginTop="@dimen/md_keylines"
android:layout_marginBottom="@dimen/md_keylines"
android:layout_marginRight="@dimen/md_keylines"
tools:text="@string/item_desc"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@color/dark_grey"
android:textSize="@dimen/article_subheading" />
<Button
android:id="@+id/action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/card_text"
style="?android:attr/borderlessButtonStyle"
android:textColor="?attr/colorPrimary"
android:text="Action" />
<ImageButton
android:id="@+id/share_button"
android:layout_width="@dimen/cards_button_width"
android:layout_height="@dimen/cards_button_height"
android:layout_marginRight="@dimen/md_keylines"
app:srcCompat="@drawable/ic_share"
android:layout_below="@+id/card_text"
android:layout_alignParentRight="true"
style="?android:attr/borderlessButtonStyle"
android:tint="@color/button_grey" />
<ImageButton
android:id="@+id/favorite_button"
android:layout_width="@dimen/cards_button_width"
android:layout_height="@dimen/cards_button_height"
android:layout_marginRight="@dimen/md_keylines"
app:srcCompat="@drawable/ic_favorite"
android:layout_below="@+id/card_text"
android:layout_toLeftOf="@id/share_button"
style="?android:attr/borderlessButtonStyle"
android:tint="@color/button_grey" />
</RelativeLayout>
【问题讨论】:
-
它只发生在 API
标签: android material-design cardview