Mat*_*des 2 android rounded-corners android-recyclerview
我正在开发一个 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>
Run Code Online (Sandbox Code Playgroud)
文件行:
<?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>
Run Code Online (Sandbox Code Playgroud)
我尝试过改变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>
Run Code Online (Sandbox Code Playgroud)
注意:这仅适用于 Lollipop+
由于圆角裁剪的成本高昂,在 Lollipop 之前的平台上,CardView 不会裁剪与圆角相交的子项。
| 归档时间: |
|
| 查看次数: |
4882 次 |
| 最近记录: |