我正在开发一个 Android 应用程序,我正在使用 recyclerview。我已经设法显示带有数据的行并对其应用设计,但我无法为行设置圆角。下面是我的 xml
文件。
名称为 rounded_corners_cards.xml
的圆角文件:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<stroke android:width="3dp"
android:color="@color/grayLight"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
行文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/StandardListRow"
android:layout_height="60dp"
android:orientation="vertical"
android:background="@drawable/rounded_corners_cards">
<ImageView
android:id="@+id/offer_picture"
style="@style/StyleRowIcon"
android:contentDescription="@string/card_offer_image"
android:scaleType="centerInside" />
</RelativeLayout>
我尝试更改 rounded_corners_cards.xml
文件,但没有成功。
感谢您的建议。
最佳答案
到目前为止,在布局上获得圆角的最简单方法是用 CardView
包裹它。通常,这将也显示阴影,但您可以使用 cardElevation
属性将其关闭。
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/StandardListRow"
android:layout_height="60dp"
app:cardCornerRadius="7dp"
app:cardElevation="0dp">
<ImageView
android:id="@+id/offer_picture"
style="@style/StyleRowIcon"
android:contentDescription="@string/card_offer_image"
android:scaleType="centerInside" />
</android.support.v7.widget.CardView>
注意:这仅适用于 Lollipop+
Due to expensive nature of rounded corner clipping, on platforms before Lollipop, CardView does not clip its children that intersect with rounded corners.
关于android - 无法在 recyclerview 中获取行的圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48602246/